Help with SQL

  • I am trying to get a sql which checks if col1 data of Table A doesnt exists in TableB (col2) and in TableC(col3). Whats the better way of getting the sql using not exists/not in. Can someone please provide an input and how to get the sql correctly. TIA

  • It will be easier for us to help you if you can provide us the table structure of the three tables in question; with sample data.

    Thanks.

    [font="Arial"]---

    Mohit K. Gupta, MCITP: Database Administrator (2005), My Blog, Twitter: @SQLCAN[/url].
    Microsoft FTE - SQL Server PFE

    * Some time its the search that counts, not the finding...
    * I didn't think so, but if I was wrong, I was wrong. I'd rather do something, and make a mistake than be frightened and be doing nothing. :smooooth:[/font]

    How to ask for help .. Read Best Practices here[/url].

  • Please also show us what you've done. We don't want to be doing homework or exam questions without you trying. We'll help you figure out what's wrong.

  • If you look at BOL (books online - the SQL Server Help function) you can find the format for both the EXISTS keyword and the IN keyword ... with EXAMPLES !!!

    Both can be used with subqueries in this fashion:

    IF (or WHERE) NOT EXISTS (select blah from table blahTbl where blahCol1 = blahCol2)

    IF (or WHERE) blahCol2 NOT IN (select blahCol1 from table blahTbl)

    If your question is simply which is the faster technique, here is some good reading.

    http://www.sqlservercentral.com/articles/Performance+Tuning/2924/

    __________________________________________________

    Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
    Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills

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

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