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.
Dig Deeper on Oracle development languages
Related Q&A from Rudy Limeback
Read SQL expert Rudy Limeback's advice for counting combinations in a table with SQL's GROUP BY clause Continue Reading
SQL expert Rudy Limeback explains how to sort an SQL UNION query using a special ORDERY BY sequence. Continue Reading
SQL expert Rudy Limeback explains how to formulate a query using an SQL SELECT statement from a non-existing table. Continue Reading