我有表products
和表product_comments
(与表products
的关系:product_id
)。现在,我需要从表 products
中删除一些产品,如果该产品在表 product_comments
中有一些记录,也删除这些记录。
PhpMyAdmin 中可以做类似的事情吗?
最佳答案
尝试
delete p, c
from products p
left outer join product_comments c on c.product_id = p.product_id
where p.product_id = 1
SQL Fiddle example
关于mysql - 同时从2个表中删除数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12568786/