Reputation:
I am writing a query to delete all customers which never ordered, I am getting below error,
Unknown table 'customers' in MULTI DELETE
DELETE customers
FROM customers as c
LEFT JOIN orders as o
ON c.customers_id = o.customers_id
WHERE o.customers_id IS NULL
Upvotes: 0
Views: 706
Reputation: 135
The basic principle is:
DELETE FROM
customers
WHERE
customers_id NOT IN (SELECT customers_id FROM orders)
But strongly recommended that you do not delete data from your table, instead you may add another colum to discriminate those customers as inactive or something like that... so you avoid using DELETE commands.
Upvotes: 1