View Single Post
  #5 (permalink)  
Old December 22nd, 2010, 03:38 PM
Old Pedant Old Pedant is offline
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Quote:
I also want to be able to find all Vendors that have only ever sold to New York , and nowhere else.
That's tougher. Hmmm...
Code:
SELECT vendorName
FROM Vendors
WHERE vendorID IN ( 
    SELECT O.VendorID 
    FROM Orders AS O, Customers AS C
    WHERE O.customerID = C.customerID AND C.State = 'NY' )
AND vendorID NOT IN ( 
    SELECT O.VendorID 
    FROM Orders AS O, Customers AS C
    WHERE O.customerID = C.customerID AND C.State <> 'NY' )
I think that will do it.
Reply With Quote
The Following User Says Thank You to Old Pedant For This Useful Post:
03jh01 (December 22nd, 2010)