Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete data from multible tables

I have two tables say table X and table Y. I want to delete all data from table X with column value = x1 and also want to delete data from table Y with column value = x1.

How can i achieve this using a single Delete statement?

Thanks

like image 382
Romi Avatar asked Jan 30 '26 04:01

Romi


2 Answers

Since you want to delete from multiple tables, you should specify the table you want to delete so you will not get syntax error.

DELETE x, y
FROM   x INNER JOIN y ON x.Col = y.Col
WHERE  x.Col = 'x1'

http://www.sqlfiddle.com/#!2/00ab7/1

like image 55
Skinny Pipes Avatar answered Feb 01 '26 20:02

Skinny Pipes


delete x,y from x,y where x.colname='x1' and y.colname='x1'

Try this query.

Hope its helpful.

like image 34
Freelancer Avatar answered Feb 01 '26 20:02

Freelancer