Home | Blog | Twitter @AndyJ | Contact Me | Snippets/Downloads | RSS

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

TweetBacks
Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
chris the great's Gravatar 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
# Posted By chris the great | 10/11/07 7:14 PM
arvind's Gravatar Awsome tip dude.. nice one .... it helped a lot for me.. thanks
# Posted By arvind | 2/4/09 10:09 AM
Janckos's Gravatar Muchas gracias!.
# Posted By Janckos | 2/9/09 11:49 AM
Jose Noriega's Gravatar Thank you.
# Posted By Jose Noriega | 5/2/09 3:31 PM
BlogCFC / created by Raymond Camden / running version 5.9.5.003 / Contact AndyJarrett.com / Pet Rescue SOS www.redgiraffes.co.uk