0
delete from table1 where user_id = ...
delete from table2 where user_id = ...
delete from table3 where user_id = ...
delete from table4 where user_id = ...

我尝试从这个 1 查询中进行,但不是结果。

4

1 回答 1

0

我认为这会奏效

DELETE table1.*, table2.*,table3.* FROM table1, table2, table3 
WHERE table1.user_id=? and table2.user_id=? and table3.user_id=?; 

还有另一种可能有效的解决方案:

DELETE FROM table1, table2, table3 
USING table1 
    INNER JOIN table2 USING(user_id) 
    INNER JOIN table3 USING(user_id) 
WHERE table1.user_id= ?

无论如何,您可以使用选项在表上定义外键约束ON DELETE CASCADE,然后从父表中删除记录会从子表中删除所有记录。

于 2013-01-30T14:52:23.470 回答