Home Forums SQL Server 2008 T-SQL (SS2K8) Left Join doesn't return all recodrs in left table RE: Left Join doesn't return all recodrs in left table

  • helal.mobasher 13209 (11/27/2012)


    I am linking two tables with left outer join. I need to keep all the records in the left table even though there are no matches in the right one. I thought that's the purpose of using left outer join. Here is the example: tab1 ID=ranges from 01 to 10 and tab2 ID ranges from 01 to 10 with missing IDs.

    select ID, Name

    from tab1 t1

    left outer join tab2 t2 on t1.id=t2.id

    results:

    t1.id,t1.name

    01,A

    02,B

    03,C

    06,F

    08,I

    since t2.ids 4,5,7,9,,10 are missing, these records are excluded from the result set.

    Any help will be greatly appreciated.

    Thanks,

    Helal

    posted query will not work becuase of ambiguity.