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

DELETE using values from another table

I am using MS Access. I have two tables: A and B. A has the fields ID, DATE and others. B has the field ID and...

others. The tables are related by the field ID. I need to eliminate some records of B depending of the value of DATE of A. How can I do this?

There are two methods. The first uses WHERE EXISTS syntax:

delete from B
 where exists
       ( select 1 from A
          where ID = B.ID
            and [DATE] = #2002-09-28# )

The second method uses WHERE IN syntax:

delete from B
 where ID in
       ( select ID from A
          where [DATE] = #2002-09-28# )

Both methods are equivalent.

By the way, I used square brackets around the column called DATE. I would strongly urge you not to name your columns using a reserved word. That's just asking for trouble, like syntax errors.

For More Information


This was last published in October 2002

Dig Deeper on Oracle and SQL

PRO+

Content

Find more PRO+ content and other member only offers, here.

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.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide.com

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close