I have a query.
DELETE FROM A
WHERE i NOT IN
( SELECT i FROM B WHERE j = 1
UNION select i from C
UNION select i from D
);
basically delete all rows in A where field i does not occur in tables B, C or D. If it was just
DELETE FROM A
WHERE i NOT IN
( SELECT i FROM B
);
then that could be done easility with a left join
DELETE A FROM A
LEFT JOIN B
ON A.i = B.i
WHERE B.id is NULL;
( Assume that every table has a id field in the schema )
I guess my question is then does the above extend to the three table scenario with the following solution?
DELETE A FROM A
LEFT JOIN B
ON A.i = B.i AND B.j = 1
LEFT JOIN C
ON A.i = C.i
LEFT JOIN D
ON A.i = D.i
WHERE B.id is NULL
AND C.id is NULL
AND D.id is NULL