Simon Grabowski wrote:
> Hi,
>
> I have two tables: table1 and table2.
> Both tables share the same 'account_id'
> column. In table1 there is a column
> 'active' which is always either 'y' (account
> active) or 'n' (account inactive).
>
> Now here is what I want to do...
>
> I want to delete all entries from table2
> with account_id matching account_id in
> table1 and having table1's active='n'.
>
> Is it possible to perform such a delete
> with one query (I know it is with SELECT)?
>
> What's the best approach here?
This is simple to perform with one query. Something like:
DELETE FROM table_2 WHERE table_2.id = table_1.id AND table_1.active =
'n'
should do the trick.
NOTE: This is not tested - try the WHERE clause with a SELECT query and
make sure that the right rows are getting returned before you unleash this
on your table. **and** backup the databases! :)
--zak
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php