Thread: Excluding Rows
View Single Post
  #2 (permalink)  
Old August 17th, 2005, 12:47 PM
Jeff Mason Jeff Mason is offline
Friend of Wrox
 
Join Date: Jun 2003
Location: Hudson, MA, USA.
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

A subquery should do the trick.

It's sometimes helpful to think of these from the "inside out":

First find the set of CUSTOMERNUMBER's which have ordered the ProductModelNumber you want to exclude:
Code:
SELECT CUSTOMERNUMBER
  FROM tbl_orders
WHERE ProductModelNumber = 'H5160R'
Then the result you are looking for are those customers NOT in this set:
Code:
SELECT DISTINCT CUSTOMERNUMBER
FROM tbl_orders
WHERE CUSTOMERNUMBER NOT IN 
    (SELECT CUSTOMERNUMBER
      FROM tbl_orders
    WHERE ProductModelNumber = 'H5160R')

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
Reply With Quote