homepage Welcome to WebmasterWorld Guest from 54.226.252.142
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

    
Just a simple question about multiple table delete syntax.
nelsonm




msg:4448565
 5:02 pm on May 2, 2012 (gmt 0)

Hi all,

I want to use a single delete statement to delete records from multiple tables.

The MySQL manual appears to say that the following two statements are functionally identical.

DELETE a1, a2 FROM t1 AS a1 INNER JOIN t2 AS a2
WHERE a1.id=a2.id;

DELETE FROM a1, a2 USING t1 AS a1 INNER JOIN t2 AS a2
WHERE a1.id=a2.id;

Am i correct?

The only difference appears to be semantic and as such, i prefer the latter "DELETE FROM a1, a2 USING" syntax. It seems more natural.

 

coopster




msg:4472746
 12:27 pm on Jul 5, 2012 (gmt 0)

You are referencing the ALIAS section of the multiple-table delete syntax on that page of the MySQL manual. But yes, you are correct. Look up a little higher on that page and you will find the statement that clarifies:

For the first multiple-table syntax, only matching rows from the tables listed before the FROM clause are deleted. For the second multiple-table syntax, only matching rows from the tables listed in the FROM clause (before the USING clause) are deleted. [...]

nelsonm




msg:4472814
 3:15 pm on Jul 5, 2012 (gmt 0)

thanks for confirming my question.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved