I have the following SQL query:
DELETE FROM table_b b WHERE NOT EXISTS (SELECT * FROM table_a a WHERE a.some_id = b.some_id)
and am getting the following error:
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'b WHERE NOT EXISTS(SELECT * FROM table_a a WHERE a.some_id = b.some_id)' at line 1
this seems to suggest that aliases cannot be used with SQL delete statements (?)
Yes you can use alias in DELETE query. Just you have use that alias after DELETE keyword than it will work. It specifies that from which table you have delete the records.
Try this:
DELETE b
FROM table_b b
WHERE NOT EXISTS (SELECT * FROM table_a a WHERE a.some_id = b.some_id)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With