List:General Discussion« Previous MessageNext Message »
From:Andy Hall Date:September 8 2003 2:02pm
Subject:SubQueries and IN
View as plain text  
Hi,

I have just started using MySQL from MSSQL 7. I need to port the following
into MySQL from an existing (working) query on MSSQL Server:

SELECT product_id, name, description
FROM products
WHERE product_id NOT IN (SELECT product_id FROM sales WHERE customer_id =
10)

i.e. get all the products that a particular customer has not already bought

This errors, and I have since read that the MySQL "IN" does not allow
sub-queries, but also seen examples of it done. Is it only supported in a
later version? We are running v. 3.23.3.

I have also tried:

SELECT product_id, name, description, sales.sale_id
FROM products LEFT JOIN sales ON products.product_id = sales.product_id
WHERE sales.customer_id = 10 AND sales.sale_id IS NULL

This does not return any records as it seems to ignoring the LEFT JOIN part
when I stick on the "WHERE sales.customer_id = 10".
(pretty sure this query would work in MS-SQL)

There must be a way to do this, but I dont seem to be able to put my finger
on it and I would appreciate any help!

Thanks

Andy Hall.

Thread
SubQueries and INAndy Hall8 Sep
  • Re: SubQueries and INSebastian Tobias Mendel genannt Mendelsohn8 Sep
  • Re: SubQueries and INChris Boget8 Sep
  • Re: SubQueries and INRoger Baklund8 Sep
    • Re: SubQueries and INAndy Hall8 Sep
  • Re: SubQueries and INEgor Egorov8 Sep
    • Re: SubQueries and INSebastian Tobias Mendel genannt Mendelsohn8 Sep
      • Re: SubQueries and INEgor Egorov8 Sep
RE: SubQueries and INAdam Fortuno8 Sep
  • Re: SubQueries and INAndy Hall8 Sep