查询有什么问题?
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执行此查询。错误未知。
另一个问题,这对我也有帮助:如果我没有索引,如何才能对行进行级联删除?
答案 0 :(得分:4)
您应该在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'
答案 1 :(得分:1)
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'
加入时,您必须指定要删除的表格。这就是delete c from ...