TSQL problem

  •  

    Table 1

    Table 2
    IdNameIdName
    1One1One
    2Two2Two
    3Three3Three
    4Four4Four
    5Five5Five
    6Six6Six
    7Seven
    8Eight
    9Nine
    10Ten
    Reqiured:
    7Seven
    8Eight
    9Nine
    10Ten

    Can anyone solve it without using JOIN or IF join used then result should be faster enough so that the performance is not an issue. Thanks.

     

    /**A strong positive mental attitude will create more miracles than any wonder drug**/

  • Have a look at NOT EXISTS in BOL.

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • You need to use a join to get the best performance.  Indexing on the id fields would also help a lot.

    select * from table2 t2

    left join table1 t1 on t2.id = t1.id

    where t1.id is null

    Regards

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Frank,

    Not Exists worked fine.

    Many Thanks, for your suggestion.

     

     

    /**A strong positive mental attitude will create more miracles than any wonder drug**/

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

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