如何从三个表中删除行 - 查询错误

时间:2016-08-05 05:26:48

标签: mysql

我需要从多个mysql表中删除行(3)。这是我的查询它显示错误,但我根据示例和教程创建此查询。

DELETE FROM customers, orders, order_detail USING customers   
INNER JOIN orders INNER JOIN order_detail   
WHERE customers.id = orders.customers_id   
  AND orders.id = order_detail.orders_id   
  AND customers.id IN (66,67,68,90,85,81,80,78,76,74,71,118,113,110,149)

enter image description here

I changed the query according to a answer for above question but the then I got a different error I coundnt find witch way is correct or what are these error.

1 个答案:

答案 0 :(得分:1)

请运行以下SELECT查询,以检查哪些条目将被删除。

SELECT 
C.*,
O.*,
OD.*
FROM customers C
INNER JOIN orders O ON C.id = O.customers_id
INNER JOIN order_detail OD ON O.id = OD.orders_id
WHERE C.id IN (66,67,68,90,85,81,80,78,76,74,71,118,113,110,149);

如果上述查询成功运行,那么您可以将此查询转换为DELETE查询:

DELETE 
C,O,OD
FROM customers AS C
INNER JOIN orders AS O ON C.id = O.customers_id
INNER JOIN order_detail AS OD ON O.id = OD.orders_id
WHERE C.id IN (66,67,68,90,85,81,80,78,76,74,71,118,113,110,149)