Delete from multiple tables in one query

Never had a need to do this till today, but here's how you can delete from three tables in one query. Below is the SQL i used on a MySQL DB.

<cfquery datasource="#request.dsn#" name="delQry">
DELETE FROM
table_1, table_2
USING
table_1, table_2
WHERE
table_1.id = table_2.id
AND
table_1.id = 1
</cfquery>


Learn more at www.mysql.com/delete

Posted: 09-Mar-2004

View: 6950

Permalink: here

Comments

Great post, bro!

I knew there had to be a way to do it but I didn't want to sift through the mysql manual. All I kept seeing on forums was "you have to use multiple queries"..."you can't do it in one querie"....

pish posh! you can, and I did thanks to you!

keep posting all the neat0 things

#1 chris the great
11/Oct/07 7:14 PM

Awsome tip dude.. nice one .... it helped a lot for me.. thanks

#2 arvind
04/Feb/09 10:09 AM

Muchas gracias!.

#3 Janckos
09/Feb/09 11:49 AM

Thank you.

#4 Jose Noriega
02/May/09 3:31 PM

Exactly what I wanted, seems this is the only solution that worked for me. Cheers man

#5 Dan
20/Jan/11 2:56 PM