Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 how to delete duplicate....

Author  Topic 

asifbhura
Posting Yak Master

165 Posts

Posted - 2006-07-18 : 08:40:40
dear

I want to delete duplicates rows from my table

waiting for reply.

regards,
ASIF

nr
SQLTeam MVY

12543 Posts

Posted - 2006-07-18 : 08:44:13
You mean if there is a duplicate then delete them all leaving none of those rows?

delete tbl
from tbl t1
join (select col1, col2, col3, ... from tbl group by col1, col2, col3, ... having count(*) > 1) t2
on t1.col1 = t2.col1
and t1.col2 = t2.col2
and t1.col3 = t2.col3
...

You would also have to deal with nulls if you have them


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-07-18 : 09:01:21
quote:
Originally posted by asifbhura

I want to delete duplicates rows from my table



Add an identity column to the table, delete unwanted rows based on identity value and then remove Identity column from the table.

Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

RyanRandall
Master Smack Fu Yak Hacker

1074 Posts

Posted - 2006-07-18 : 10:44:12
Here's a related link - including an example of the method Harsh suggests...

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=69173


Ryan Randall
www.monsoonmalabar.com London-based IT consultancy

Solutions are easy. Understanding the problem, now, that's the hard part.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-07-22 : 06:20:14
Also refer http://sqlteam.com/forums/topic.asp?TOPIC_ID=6256

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -