Subqeries require mysql 4.1.

The manual offers some suggestions on rewriting subqueries as JOINs <http://dev.mysql.com/doc/mysql/en/Rewriting_subqueries.html>.

In your case, you want something like:

  SELECT product FROM products p
  LEFT JOIN products_by_product_areas a ON p.product = a.product
  WHERE a.product IS NULL;

Michael

Anton Ivanov wrote:

Hi,  I'm trying to figure out how to apply these from the manual, but to
no avail.  Is it possible that my version (4.0.18) does not implement
these?
I have two tables: products and products_by_product_area.  Both have a
field "product".  I try

SELECT product from products WHERE NOT EXISTS (SELECT DISTINCT * from
products_by_product_areas WHERE products_by_product_areas.product =
products.product);

Both of these queries run fine on their own.  It looks to me that I'm
simply adapting from the manual, but all I get is

ERROR 1064: You have an error in your SQL syntax.  Check the manual that
corresponds to your MySQL server version for the right syntax to use
near 'EXISTS (SELECT DISTINCT * from products_by_product_areas WHERE

OK, so I grab the example verbatim from the manual:
SELECT DISTINCT store_type FROM Stores
  WHERE EXISTS (SELECT * FROM Cities_Stores
                WHERE Cities_Stores.store_type = Stores.store_type);

And run it.  Same error.  Never mind that I don't have these tables: the
query does not compile.  What is going on?




--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to