Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > SQL Language
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Display Modes
  #1 (permalink)  
Old October 17th, 2006, 02:27 AM
Registered User
Join Date: May 2004
Location: , , Belgium.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Fysicus Send a message via AIM to Fysicus Send a message via MSN to Fysicus Send a message via Yahoo to Fysicus
Default IN versus LEFT JOIN (differences?)

 Yesterday I was asked to check 2 tables for differences. First I tried it using the IN operaror:

        SELECT * FROM Table1 where not(Table1.ID IN (SELECT Table2.ID
                                                     FROM Table2))

I knew there were supposed to be several differences between the tables, weirdly enough using this query I didn't find any.

Afterwards I tried it using a LEFT JOIN:

        SELECT * FROM Table1 LEFT JOIN Table2
        ON Table1.ID = Table2.ID

I made a view of this query, and when I checked for cases where Table2.ID was NULL I suddenly found my differences.

Personally I'm baffled by this. Does anyone here have an explanation for this?

Logically, at least that was what I thought, my 1st query should have sufficed, but it didn't yield anything.

Please help. This may sound like a newbie question, but I really would like to know what I did wrong.

Reply With Quote
  #2 (permalink)  
Old October 17th, 2006, 05:22 AM
Friend of Wrox
Join Date: Jun 2003
Location: Hudson, MA, USA.
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post

Do you have NULL as a value for the ID column in Table2?

The IN clause is shorthand for an equality test of a value with a list of values. If NULL is a value in the list, the equality test will result in unknown. Thus, it is not possible to know for sure that any given value isn't in the list because of that unknown result, so no rows are returned by NOT...IN.

Welcome to three valued logic...

Jeff Mason
Custom Apps, Inc.
Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Order the Ages - Left/Right versus "clockwise" gmlewis BOOK: Puzzles for Programmers and Pros BOOK ISBN: 978-0-470-12168-9 0 July 24th, 2007 01:04 PM
left outer join keyvanjan Classic ASP Professional 0 February 5th, 2006 10:54 AM
Why doesn't this LEFT JOIN work? harg7769 Access 2 April 13th, 2005 04:49 AM
left join msrnivas Classic ASP Databases 2 October 15th, 2004 07:37 AM
Oracle 8i inner join and left join problem puteri_84 Oracle 2 August 19th, 2004 07:14 AM

All times are GMT -4. The time now is 07:13 AM.

Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.