I need to delete all the duplicates, all but one, for each of the table ids. Like the following. I need to delete all the duplicates on valueid for 01,02,03...
Original:
id | valueid | data ____________________________ 01 | 1001 | datadata1 01 | 1002 | datadata2 01 | 1001 | datadata1 02 | 1323 | datamoredata123 02 | 1323 | datamoredata123 03 | 22123 | evenmoredata 03 | 24444 | andalsomore Should end like:
id | valueid | data ____________________________ 01 | 1001 | datadata1 01 | 1002 | datadata2 02 | 1323 | datamoredata123 03 | 22123 | evenmoredata 03 | 24444 | andalsomore Was trying to do it with something like this, but I don´t get how can I group that delete on the id
WITH CTE AS( SELECT valueid, RN = ROW_NUMBER()OVER(PARTITION BY valueid ORDER BY valueid) FROM tblvalues ) DELETE FROM CTE WHERE RN > 1 Any suggestions?
Thanks in advance