-- List all Duplicates
select m1.lastname, m1.firstname, m1.email, m1.zipcode
from tblMain m1
inner join tblMain m2
on isnull(m1.lastname, '') = isnull(m2.lastname, '')
and isnull(m1.firstname, '') = isnull(m2.firstname, '')
and isnull(m1.email, '') = isnull(m2.email, '')
and isnull(m1.zipcode, '') = isnull(m2.zipcode)
and m1.ID <> m2.ID
order by 1, 2, 3, 4
Чтобы удалить последние дубликаты, используйте что-то вроде:
delete from tblMain
where ID in
(
select m1.ID
from tblMain m1
inner join tblMain m2
on isnull(m1.lastname, '') = isnull(m2.lastname, '')
and isnull(m1.firstname, '') = isnull(m2.firstname, '')
and isnull(m1.email, '') = isnull(m2.email, '')
and isnull(m1.zipcode, '') = isnull(m2.zipcode)
and m1.ID > m2.ID
)