September 8, 2011 at 2:28 pm
I have a table where there are around 18000 duplicate rows. These duplicates are exactly duplicates of each other including the timestamps. So I cannot delete using the delete statements.
I have identified the duplicates by this query: and I found 18000 rows.
SELECT appt_id, event_id, count(*)
FROM appointments
GROUP BY appt_id, event_id
HAVING count(*) > 1
Now how do i delete all these duplicate rows in a table? Any help is really appreciated
September 8, 2011 at 5:25 pm
You could use something like this CTE
;with numbered as(SELECT rowno=row_number() over
(partition by appt_id, event_id order by appt_id),appt_id, event_id from
appointments)
select * from numbered
Once your sure it is correct, then the SELECT * statement could be changed to DELETE FROM numbered where Rowno > 1
September 8, 2011 at 11:20 pm
just use this query in low traffic time.
SELECT distinct * INTO NEWTable FROM OldTable
delete the old table or drop the old table. if no index is used.
OR
truncate the old table after checking the new table.
and
insert into oldtable select * from new table
and drop the old table.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply