• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 680
  • Last Modified:

How do I delete unmatched records between two tables

I have two tables, table1 and table 2.  Table 2 has some records that are not in Table 1. I need to delete those records from table 1 so both tables contain only same records. in the example deleting records 2 and 4 from Table2. I have close to 100K records, hence diut it manuuly is out of a question.

TABLE1.ID             TABLE2.ID
1                             1
3                             2
5                             3
                               4
                               5

0
RalphyC
Asked:
RalphyC
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
this should do:
DELETE * FROM Table2
WHERE ID NOT IN (SELECT ID FROM TABLE1)

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now