查询有什么问题?
delete from categories c
left join categories_products cp on cp.category_id = c.id
left join products p on p.id = cp.product_id
left join images i on i.object_id = cp.product_id
where c.id = 3 and i.site_section = 'products'
MySQL 返回错误。我正在尝试通过 HeidiSQL 执行此查询。错误未知。
另一个问题也对我有帮助:如果我没有索引,如何级联删除行?
最佳答案
您应该在delete
关键字后添加别名
DELETE c FROM categories c
LEFT JOIN categories_products cp
on cp.category_id = c.id
LEFT JOIN products p
on p.id = cp.product_id
LEFT JOIN images i on i.object_id = cp.product_id
WHERE c.id = 3 and i.site_section = 'products'
关于mysql - 查询出了什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11668822/