I have a query that pulls data from a duplicate query. I need to make this query a subquery of a delete query--delete entries that are duplicate in a table--deleting data from the table tblEmail. I tried writing the SQL myself, but it gives an error.
This is the original query code:
This is my modified code incorporating the subquery (it gives an error message)
I'd appreciate any help you can offer. I don't have much experience with sub-queries, so I may be going about this all wrong.
This is the original query code:
Code:
SELECT [Find duplicates for tblEmail].*
FROM [Find duplicates for tblEmail]
WHERE ((([Find duplicates for tblEmail].UniqueIDNum) Not In (Select Min(t2.UniqueIDNum) as MinId from [Find duplicates for tblEmail] as t2 group by t2.[PhoneNumber], t2.[EmailAddress]
This is my modified code incorporating the subquery (it gives an error message)
Code:
DELETE UniqueIDNum, PhoneNumber, EmailAddress
FROM tblEmail
WHERE tblEmail.UniqueIDNum IN (SELECT [Find duplicates for tblEmail].*
FROM [Find duplicates for tblEmail]
WHERE ((([Find duplicates for tblEmail].UniqueIDNum) Not In (Select Min(t2.UniqueIDNum) as MinId from [Find duplicates for tblEmail] as t2
GROUP BY
t2.[PhoneNumber], t2.[EmailAddress]))));
I'd appreciate any help you can offer. I don't have much experience with sub-queries, so I may be going about this all wrong.