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 and SQL
Related Q&A from Rudy Limeback
Read an example of an SQL case expression from our SQL expert Rudy Limeback. Continue Reading
Read SQL expert Rudy Limeback's advice for counting combinations in a table with SQL's GROUP BY clause Continue Reading
Read about the Mimer Validator, a tool used to verify your SQL code, in this tip from SQL expert Rudy Limeback. Continue Reading