How can I delete duplicate rows where no unique row id
exists?
My table is
col1 col2 col3 col4 col5 col6 col7
john 1
You need to group by the duplicate records according to the field(s), then hold one of the records and delete the rest. For example:
DELETE prg.Person WHERE Id IN (
SELECT dublicateRow.Id FROM
(
select MIN(Id) MinId, NationalCode
from prg.Person group by NationalCode having count(NationalCode ) > 1
) GroupSelect
JOIN prg.Person dublicateRow ON dublicateRow.NationalCode = GroupSelect.NationalCode
WHERE dublicateRow.Id <> GroupSelect.MinId)