views:

41

answers:

3

Hi there.

I have 2 tables one called "REVIEW" and the other "REVIEW_DESCRIPTION"

if i do a join to get all the data from both:

SELECT *
FROM reviews 
INNER JOIN reviews_description
ON reviews.reviews_id=reviews_description.reviews_id
WHERE reviews.customers_id = 54183

based on this i would like to delete rows in both tables that match this criteria in one shot, any tips?

thanks!

A: 

would cascade delete help?

akonsu
+1  A: 

Unless you have on cascade delete or a delete trigger setup you need to use 2 statements

SQLMenace
Not correct for MySQL: http://dev.mysql.com/doc/refman/5.0/en/delete.html
OMG Ponies
+2  A: 

Yes, MySQL supports deletions from more than one table in a single statement:

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. The effect is that you can delete rows from many tables at the same time and have additional tables that are used only for searching...

First multi-table syntax example:

DELETE reviews, reviews_description 
  FROM reviews r
  JOIN reviews_description rd
 WHERE reviews.reviews_id = reviews_description.reviews_id
   AND reviews.customers_id = 54183
OMG Ponies
Cool. didn't know mysql supported something like that.
Matt H
didn't know this either +1
SQLMenace
@OMG Ponies THANK YOU!
sebb