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
- Dozens more answers to tough SQL questions from Rudy Limeback.
- The Best SQL Web Links: tips, tutorials, scripts, and more.
- Have an SQL tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize. Submit your tip today!
- Ask your technical SQL questions -- or help out your peers by answering them -- in our live discussion forums.
- Ask the Experts yourself: Our SQL, database design, Oracle, SQL Server, DB2, metadata, object-oriented and data warehousing gurus are waiting to answer your toughest questions.
This was first published in October 2002