Doubt Left Join

  • 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 =

  • 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.

  • 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

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply