Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete rows from multiple tables at once

Tags:

php

mysql

I'm trying to combine 2 queries into one like this

$result=$db->query ("DELETE FROM menu WHERE name = '$new'") or die($db->error);
$result=$db->query ("DELETE FROM pages WHERE title = 'new'") or die($db->error);

Into

$result=$db->query ("DELETE FROM menu AS m, pages AS p WHERE m.name = 'new' AND p.title='new'") or die($db->error);

But DB gives syntax error. What's wrong?

like image 250
heron Avatar asked Dec 16 '22 08:12

heron


1 Answers

DELETE operations have to be done one table at a time. There's no way to combine them as you are trying to do. Depending on what you're trying to accomplish, you may want to use a transaction for the two operations.

like image 185
Joe Stefanelli Avatar answered Jan 01 '23 19:01

Joe Stefanelli