delete duplicates

D

Darren

I have one table (table 1) with a column A & B and another table (table 2)
with columns C & D. Now there are duplicates in table 2 on the values in
column C. I need to keep the entries where 1A=2C and 1B=2D and delete the
entries where 1A=2C and 1B does not = 2D

please help
 
A

Allen Browne

So you want to keep the entries where Table1.A = Table2.B and Table1.C =
Table2.D, and delete the non-matching entries from table1?

DELETE FROM Table1
WHERE NOT EXISTS
(SELECT B FROM Table2
WHERE Table1.A = Table2.B and Table1.C = Table2.D);

If subqueries are new, here's an introduction:
http://allenbrowne.com/subquery-01.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top