Re: Curious SQL question

From: Walt <wamitty_at_verizon.net>
Date: Wed, 03 Jan 2007 14:47:01 GMT
Message-ID: <FlPmh.4$5g.1_at_trndny01>


"Guto" <gutomore_at_gmail.com> wrote in message news:1167826602.405469.312020_at_48g2000cwx.googlegroups.com...
> 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?
>
> Regards
> Carlos Augusto
>

Look up the MINUS operator or the WHERE NOT EXISTS construct. There are other ways, but start with these.

Youy are probably going to want a Customer table sometime in the future. Why not model it now? Received on Wed Jan 03 2007 - 15:47:01 CET

Original text of this message