I have following data:
Id: 1 Name: apple ForeignKey: 10 Id: 2 Name: apple ForeignKey: 10 Id: 3 Name: apple ForeignKey: 15 Id: 4 Name: peach ForeignKey: 11 Id: 5 Name: peach ForeignKey: 12
Rows with same Name and ForeignKey are duplicates in my case. Now I want to remove all the duplicates except one instance from the table.
In other words; I want to remove all rows but one, where Name and ForeignKey are equal.
In case with upper data only the row with Id 2 OR Id 1 should be removed.
With
select count(Name), Name, ForeignKey group by Name, ForeignKey having count(Name)>1
I am able to find items where more than 1 row with same Name and Foreign key exist, but how to get the IDs of those rows? And how to get the IDs of those rows except the first/last occurrence of that row with same Name and ForeignKey?
(Name,ForeignKey)(once you've removed the duplicates once)