Monday, June 1, 2009

Delete Duplicate rows

Following Query Format Helps to delete duplicate records from a SQL Table

SET ROWCOUNT 1
DELETE yourtable
FROM yourtable a
WHERE (SELECT COUNT(*) FROM yourtable b WHERE b.name1 = a.name1 AND b.age1 = a.age1) > 1
WHILE @@rowcount > 0
DELETE yourtable
FROM yourtable a
WHERE (SELECT COUNT(*) FROM yourtable b WHERE b.name1 = a.name1 AND b.age1 = a.age1) > 1
SET ROWCOUNT 0

2 comments:

  1. I can't understood.Plz clear it as soon as possible. Thanks.

    ReplyDelete
  2. Hi Manas,

    Thanks for visiting my site, tell me what you are not understand here?

    ReplyDelete