"Adam Clauss" <[EMAIL PROTECTED]> wrote:
> I have a table which maintains a list of categories and has a field called
> catID. This field is a one-to-many relationship with another table.
> What I want to do is remove any "empty" categories - aka: remove any
> categories which aren't used in the second table.
>
> I thought MySQL at least partially supported nested SELECT queries, but
> either it does not support them in DELETE's or I got the syntax wrong.
> Here's what I was trying to use:
> DELETE FROM Categories WHERE NOT(catID IN (SELECT DISTINCT catID FROM
> items));
>
> Any easy alternatives here?
In v4.0 you can rewrite as:
DELETE Categories
FROM Categories LEFT JOIN items ON Categories.catID=items.catID
WHERE items.catID IS NULL.
--
For technical support contracts, goto https://order.mysql.com/?ref=ensita
This email is sponsored by Ensita.net http://www.ensita.net/
__ ___ ___ ____ __
/ |/ /_ __/ __/ __ \/ / Victoria Reznichenko
/ /|_/ / // /\ \/ /_/ / /__ [EMAIL PROTECTED]
/_/ /_/\_, /___/\___\_\___/ MySQL AB / Ensita.net
<___/ www.mysql.com
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]