Playing with LEFT JOIN

  • CREATE TABLE T1

    (

    name varchar(10),

    id int

    )

    GO

    INSERT INTO t1

    select 'ABC' , 1

    UNION

    select 'eee' , 2

    UNION

    select 'ggg' , 4

    GO

    CREATE TABLE T2

    (

    name varchar(10),

    id int

    )

    GO

    INSERT INTO t2

    select 'ABC' , 1

    UNION

    select 'ggg' , 4

    how can i fetch the names from t1 which dont exist in table t2 (using left join)

    means i want only second record from below query

    SELECT t1.name,t2.name

    FROM t1

    LEFT JOIN t2

    ON t1.id = t2.id

    i only have to use LEFT JOIN

    -------Bhuvnesh----------
    I work only to learn Sql Server...though my company pays me for getting their stuff done;-)

  • Will this do?

    Select * from T1

    LEFT JOIN T2

    ON T1.id = T2.id

    Where T2.Id IS NULL

    ---------------------------------------------------------------------------------

  • Thanks 🙂

    -------Bhuvnesh----------
    I work only to learn Sql Server...though my company pays me for getting their stuff done;-)

  • Bhuvnesh (10/22/2009)

    i only have to use LEFT JOIN

    Why ? Not in , not exists or except can be more efficient.



    Clear Sky SQL
    My Blog[/url]

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

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