Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
smile
Starting Member
22 Posts |
Posted - 2009-03-22 : 19:25:11
|
| Hello again!My question may be is quite easy one but I really don't get it.Having this two queries:select contactname from customers where customerid in(select customerid from orders where orderid not in (select orderid from orderdetails where productid in(select productid from products where productname ='ABC')))select contactname from customers where customerid not in(select customerid from orders where orderid in (select orderid from orderdetails where productid in(select productid from products where productname ='ABC')))I expected them to retrieve the same data records...but they didn't and I still can't comprehend it... |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-03-23 : 02:47:05
|
First query gives you customer who - have orders- but only orders without product ABCSecond query gives you customer who- have orders without product ABC- have no orders No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
smile
Starting Member
22 Posts |
Posted - 2009-03-23 : 03:42:02
|
| Yes...I see that...then both will give me the customers, that don't have orders of the product'ABC'....right? So why the result is not the same..? |
 |
|
|
karthik_padbanaban
Constraint Violating Yak Guru
263 Posts |
Posted - 2009-03-23 : 03:53:10
|
| post some sample data if possible..Karthik |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-03-23 : 04:45:15
|
quote: Originally posted by smile Yes...I see that...then both will give me the customers, that don't have orders of the product'ABC'....right? So why the result is not the same..?
quote: then both will give me the customers, that don't have orders of the product'ABC'....right?
No, that is not right.The second query additional gives you customers without ANY orders! No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|