How to use sub query in MySQL DELETE statement?
Khanh Nam Do
1 min read
Just simple as bellow:
DELETE FROM clients
WHERE id NOT IN (
SELECT * FROM (
SELECT c.id
FROM products p
INNER JOIN clients c
ON c.id = p.supplier_id
WHERE c.name = 'Q-IMAGING AUSTRALIA LTD (HEAD OFFICE)'
GROUP BY c.id
) client_tbl
)
AND name = 'Q-IMAGING AUSTRALIA LTD (HEAD OFFICE)'
AND type = 'Supplier'
0
Subscribe to my newsletter
Read articles from Khanh Nam Do directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Khanh Nam Do
Khanh Nam Do
Khanh is a full stack web developer with over 15 years of experience developing for the web