I have two tables A and B. I would like to delete all records from table A that are returned in the following query:
SELECT A.* FROM A , B WHERE A.id = B.a_id AND b.date < '2008-10-10'
I tried:
DELETE A WHERE id in ( SELECT a_id FROM B WHERE date < '2008-10-10')
but this only works if the internal selection actually returns a value (not if the result set is empty)
NB: this should work on and SQLServer AND MySQL
EDIT: additional information
The above deletion works 100% on SQLServer
When starting up in MySQL, I get a "SQL syntax error" message indicating the beginning of SELECT as a problem. if I substitute the inner choice with (1,2), then it works.
@Kibbee. You are right, it doesnβt really matter if the internal selection returns rows or not.
@Fred I get the message "not unique table.alias: a"
source share