SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Doubt Left Join


Doubt Left Join

Author
Message
vinodpec
vinodpec
SSC Rookie
SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)

Group: General Forum Members
Points: 38 Visits: 102
Please explain different between the queries

SELECT *
FROM EmpAddress addr
LEFT JOIN EmpEducation edu
ON addr.empid = edu.empid
--WHERE EDU.EMPID IS NULL
WHERE addr. AddType = 2


SELECT *
FROM EmpAddress addr
LEFT JOIN EmpEducation edu
ON addr.empid = edu.empid AND addr. AddType =
Deeptiprasad
Deeptiprasad
SSC Veteran
SSC Veteran (206 reputation)SSC Veteran (206 reputation)SSC Veteran (206 reputation)SSC Veteran (206 reputation)SSC Veteran (206 reputation)SSC Veteran (206 reputation)SSC Veteran (206 reputation)SSC Veteran (206 reputation)

Group: General Forum Members
Points: 206 Visits: 263
Is this Left outer join?

If yes.
1. "addr.empid = edu.empid"-----This is join condition
2. "addr. AddType = 2"----This is filter condition

filter condition should not be mixed with join condition. But in this scenario there should not be any difference in the resultset of both.
MVDBA
MVDBA
Hall of Fame
Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)

Group: General Forum Members
Points: 3131 Visits: 860
vinodpec (4/28/2010)
Please explain different between the queries

SELECT *
FROM EmpAddress addr
LEFT JOIN EmpEducation edu
ON addr.empid = edu.empid
--WHERE EDU.EMPID IS NULL
WHERE addr. AddType = 2


SELECT *
FROM EmpAddress addr
LEFT JOIN EmpEducation edu
ON addr.empid = edu.empid AND addr. AddType =


the 1st query will show only results where from empaddress where addtype=2 - it will then join edu table and show those fields as well (but will not use this to limit rows returned)

the second query will will show all records from empaddress regardless off addtype and will then join edu table and show any related data - again it will not be used to filter the record set

query 1 will return less records
query 2 will have more blank data in the columns for edu table where the addr table <>2

MVDBA
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search