View Single Post
  #11 (permalink)  
Old December 22nd, 2010, 06:39 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

And before you ask, let's show one more simple variation on that:
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 IN('WA','OR','CA') ) 
AND vendorID NOT IN (
      SELECT O.VendorID
      FROM Orders AS O, Customers AS C
      WHERE O.customerID = C.customerID 
        AND C.State IN ('ME','NH','VT','MA','CT','RI') )
That gets all vendors who have sold in the 3 West Coast states but have never sold to any state in New England. Okay? You can see there are lots of ways to vary this.
Reply With Quote
The Following User Says Thank You to Old Pedant For This Useful Post:
03jh01 (December 22nd, 2010)