Step1: Lets say you want to find the duplicate records for a pair of attributes c1 and c2
Find all duplicate records:
SELECT c1, c2,count(1)
FROM MyTable
GROUP BY c1,c2
Step 2: Finding the row that you want to keep. Lets say you want to keep only the maximum value of some indentifier column
SELECT c1, c2,max(id)
FROM MyTable
GROUP BY c1,c2
Step 3: keep that and delete others
Delete from mytable
where id not in (
SELECT c1, c2,max(id)
FROM MyTable
GROUP BY c1,c2
)
Rocky you said Duplicate records, if id column is unique then its not a duplicate record at all. ;).
ReplyDeleteI did not know you had converted this place to a tech-blog :)
ReplyDeleteThe feed goes in the reader now.. Keep blogging such kind of stuff, helps your fellow database developers :D