我需要从多个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)
答案 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)