0

I need to delete rows from multiple mysql tables (3). this is my query it show a error but I create this query according to the examples and tutorials.

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.

KBK
  • 375
  • 1
  • 4
  • 20
  • I saw you previously posted this and later deleted. Now you are re-posting it. By the way, please share an **sql fiddle** – 1000111 Aug 05 '16 at 05:29
  • Already answered here : http://stackoverflow.com/questions/4839905/mysql-delete-from-multiple-tables-with-one-query?rq=1 – Govind Samrow Aug 05 '16 at 05:36

1 Answers1

1

Please run the following SELECT query in order to check which entries are going to be deleted.

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);

If the above query ran successfuly then you can convert this query to a DELETE query:

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)
1000111
  • 13,169
  • 2
  • 28
  • 37