Re: Curious SQL question

From: Tonkuma <tonkuma_at_jp.ibm.com>
Date: 4 Jan 2007 22:59:22 -0800
Message-ID: <1167980362.387874.76620_at_38g2000cwa.googlegroups.com>


Guto wrote:
> WOW!
> Thanks for so many posts!
> Facing the doubts about my question, heres a "picture" wich describes
> it best than
> my poor english ;o)
>
> --here's the first table:
>
> create table products(
> product_id integer,
> product_name char(20));
>
> --then the second
> create table orders(
> customer_id integer,
> product_id integer);
>
> --The products to be boughted:
> insert into products values ( 1 , "PIZZA");
> insert into products values ( 2 , "BLACK BEER");
> insert into products values ( 3 , "WHITE BEER");
> insert into products values ( 4 , "ANOTHER BEER");
> insert into products values ( 5 , "ICE COLDED BEER");
>
> --the customers who bought something:
> insert into orders values ( 1,1);
> insert into orders values ( 1,2);
> insert into orders values ( 1,3);
> insert into orders values ( 1,4);
>
> insert into orders values ( 2,1);
> insert into orders values ( 2,2);
>
> insert into orders values ( 3,1);
> insert into orders values ( 3,3);
> insert into orders values ( 3,4);
>
> insert into orders values ( 4,5);
>
> --I want this list:
>
> --The customer 1 didn't bought the product 5
>
> --The customer 2 didn't bought the product 3
> --The customer 2 didn't bought the product 4
> --The customer 2 didn't bought the product 5
>
> --The customer 3 didn't bought the product 2
> --The customer 3 didn't bought the product 5
>
> --The customer 4 didn't bought the product 1
> --The customer 4 didn't bought the product 2
> --The customer 4 didn't bought the product 3
> --The customer 4 didn't bought the product 4
>
> --And as have tried this ( at least first obvious attempt didn't
> works)
> Select customer_id, product_id from orders
> where product_id not in ( select product_id from products )
>
> I hope i was a little bit clear this time!
> Thanks Indeed!
>
> Regards,
> Guto.
>

Although, data types are different, don't my(Tonkuma) posts help you? Received on Fri Jan 05 2007 - 07:59:22 CET

Original text of this message