Re: Brain Dead on SQL statement
- From: Jon Purvis <jon.purvis@xxxxxxxxxxxxxxxx>
- Date: Tue, 26 Feb 2008 10:42:38 -0600
Mark A. Smith wrote:
Typical Customer, Orders, Items table layout. Which Customers HAVE NOT purchased Item3, But HAVE purchased Item1 OR item2?
TIA
Tested against an Access 2002 database. Seems to work, but I would not be surprised if there were a faster way.
SELECT DISTINCT People.ID
FROM (People INNER JOIN Transactions ON People.ID=Transactions.ID)
INNER JOIN Purchases ON
Transactions.Invoice_Number=Purchases.Invoice_Number
WHERE Purchases.Item_Code in ('WFD','COMP')
AND People.ID NOT IN
(SELECT People.ID
FROM (People INNER JOIN Transactions ON People.ID=Transactions.ID)
INNER JOIN Purchases ON
Transactions.Invoice_Number=Purchases.Invoice_Number
WHERE Purchases.Item_Code='HRU')
--
Jon Purvis
Wildlife Technical Programs Lead
Texas Parks and Wildlife Department
Austin, TX
.
- References:
- Brain Dead on SQL statement
- From: Mark A. Smith
- Brain Dead on SQL statement
- Prev by Date: Re: Problem with bit field using MS Sql server and Turbo Delphi 2006
- Next by Date: Re: Transactin and Rollback.
- Previous by thread: Brain Dead on SQL statement
- Next by thread: Transactin and Rollback.
- Index(es):