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 2005 Forums
 Transact-SQL (2005)
 Delete Duplicate records from table

Author  Topic 

ranjeetsingh_6
Posting Yak Master

125 Posts

Posted - 2009-02-27 : 03:40:42
Hi,

I was attend a interview at last week and face a question that
How duplicate records will deleted from a table and not use like
this approach to Eliminate the duplicate records into SELECT DISTINCT into a temporary table, truncate the original table and SELECT the records back into the original table.
which are mention at link

http://www.sqlteam.com/article/deleting-duplicate-records

Note:- Interviewer does not want way like above link
He want delete duplicate records without use of any temprory table.


Ranjeet Kumar Singh

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-02-27 : 03:45:32
Try this once,

delete t from
( select row_number() over ( partition by col order by col ) as rn from urtable) t
where t.rn > 1
Go to Top of Page

ranjeetsingh_6
Posting Yak Master

125 Posts

Posted - 2009-02-27 : 03:54:29
Thanks a lot.................

Ranjeet Kumar Singh
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-02-27 : 03:56:34
see this link to delete the duplicate records by cte& row_nuber functions

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=120411
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-02-27 : 03:58:21
quote:
Originally posted by ranjeetsingh_6

Thanks a lot.................

Ranjeet Kumar Singh



Welcome
Go to Top of Page
   

- Advertisement -