DELETE WHERE NOT EXISTS
I have two tables, A1 and A2, and they both have a column called SSn. How will I delete a row from table A2 that doesn't exist on A1?
I have one simple question. Hopefully someone can help me. I have two tables, A1 and A2, and they both have a column called SSn. How will I delete a row from table A2 that doesn't exist on A1?
You would do it almost word for word exactly like you said it.
delete from A2 where not exists ( select * from A1 where A1.SSn = A2.SSn )
Alternatively, you can also say:
delete from A2 where SSn not in ( select SSn from A1 )
Slightly different approaches, same result.