Q
Problem solve Get help with specific problems with your technologies, process and projects.

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.

This was last published in October 2005

Dig Deeper on Oracle and SQL

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide.com

SearchDataCenter

SearchContentManagement

SearchHRSoftware

Close