Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 1st, 2004, 10:02 AM
Registered User
 
Join Date: Jul 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to zobi
Default Help..!

Hi every body,
Could u plz. take a look to these two quries, they seems to me that they r equal, but they return different result sets back WHY?.
Note: - i v got the correct result from the first one.
        - i need to return tuples in Rel1 who have (a1,a2,a3) values not in Rel2
I
SELECT a0, a1, a2, a3
  FROM Rel1 WHERE (a1, a2, a3) NOT IN
      (SELECT b1, b2, b3 FROM Rel2)

II
SELECT a0, a1, a2, a3
  FROM Rel1 WHERE NOT EXISTS
   (SELECT r1.a1, r1.a2, r1.a3
       FROM Rel1 r1, Rel2 r2
          WHERE r1.a1=r2.b1 AND r1.a2=r2.b2 AND r1.a3=r2.b3)



 
Old August 1st, 2004, 12:40 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

The second one you could use not in also in your query. Does that match them up?

Brian
 
Old August 1st, 2004, 04:23 PM
Registered User
 
Join Date: Jul 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to zobi
Default

Hi Brian,
First thanks for replaying; Second, what exactly, i am trying to do is using "NOT EXISTS" instead of "NOT IN" (more efficient ).
So, i have rewritten the first one using "NOT EXISTS", but it returns a different result set. My question is are they equivalent? or not? .
thanks


 
Old August 1st, 2004, 06:16 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

From this article: http://www.devx.com/dbzone/Article/9570. It seems like that they may not be quite the exact same thing...

Brian









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.