2

查询有什么问题?

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 执行此查询。错误未知。

另一个问题,这也对我有帮助:如果我没有索引,如何对行进行级联删除?

4

2 回答 2

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'
于 2012-07-26T12:08:58.623 回答
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 ...

于 2012-07-26T12:02:01.820 回答