Re: Curious SQL question

From: Bob Badour <bbadour_at_pei.sympatico.ca>
Date: Wed, 03 Jan 2007 14:10:19 GMT
Message-ID: <fPOmh.40000$cz.591089_at_ursa-nb00s0.nbnet.nb.ca>


Lennart wrote:

> Guto wrote:
> 

>>Hi There!
>>If I have two tables:
>>
>>Products
>>-Product_ID
>>-Product_Name
>>
>>and
>>
>>Orders
>>-Customer_ID
>>-Product_ID
>>
>>
>>How can I find out what products, each customer DIDN'T bought?
>>
>>I tried lots of SQL sentences, but I can onlye get it solved, through a
>>Stored Procedure.
>>
>>
>>The obvius does not work:
>>
>>Select Customer_ID, Product_ID from Orders
>>where Product_ID not in ( select Product_id from Products )
>>
>>Any Tips?
> 
> I assume you miss one relation here, namely Customer. I think this is
> what you are looking for:
> 
> (Customer x Product) - Orders

Assuming he really has no Customers relation, he could project it from Orders.

Perhaps a more instructive question would be: How does one identify those customers who bought no products at all? Received on Wed Jan 03 2007 - 15:10:19 CET

Original text of this message