Jump to content


Photo

Deleting from two tables with one statement


  • Please log in to reply
2 replies to this topic

#1 timtom3

timtom3
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 30 November 2005 - 12:49 PM

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?

#2 widgetapps

widgetapps
  • Members
  • Pip
  • Newbie
  • 8 posts
  • LocationToronto

Posted 30 November 2005 - 01:47 PM

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]

#3 timtom3

timtom3
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 30 November 2005 - 02:18 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users