Click to search Andy Jarrett.co.uk RSS feed

Loading Twitter

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

Comments Comments (4) | Print Print | Send Send | 5188 Views

If you like what you see on the website and/or this post has helped you out in some way please consider donating to help keep me in beer vodka. The donations are made through Paypal, which accepts almost any credit card or eCheck.

(Comment Moderation is enabled. Your comment will not appear until approved.)
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
arvind's Gravatar Posted By arvind @ 2/4/09 10:09 AM
Awsome tip dude.. nice one .... it helped a lot for me.. thanks
Muchas gracias!.
Thank you.
BlogCFC by Raymond Camden + Twitter @AndyJ + ColdFusion jobs + Contact Me + Snippets/Downloads + RSS .