Jump to content

Archived

This topic is now archived and is closed to further replies.

timtom3

Deleting from two tables with one statement

Recommended Posts

Is it possible to delete information from two tables with one delete statement?

 

For example

 

DETELE * FROM product p, images i WHERE product_id.p = images_id.i ?

 

Becuase when I try this it doesn't work?

Share this post


Link to post
Share on other sites

You certainly can, but your syntax is off a little.

 

[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']DELETE[/span] t1, t2 FROM t1, t2, t3 WHERE t1.id=t2.id AND t2.id=t3.id;

[!--sql2--][/div][!--sql3--]

 

You can get all the details you need in the MySQL documentation as well:

 

[a href=\"http://dev.mysql.com/doc/refman/4.1/en/delete.html\" target=\"_blank\"]http://dev.mysql.com/doc/refman/4.1/en/delete.html[/a]

Share this post


Link to post
Share on other sites

Something wrong with this???

DELETE FROM product p, images i WHERE p.product_ID = '.$product_ID.' AND i.prod_id = '.$product_ID.' 

 

Product table

Product_ID (primary key)

 

Image table

prod_id has to match product_id

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.