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
 General SQL Server Forums
 New to SQL Server Programming
 How to delete

Author  Topic 

Joshrinn
Posting Yak Master

118 Posts

Posted - 2012-06-13 : 08:17:00
How can I delete duplicate rows from my table. Can you please post the query with imaginary table name

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-06-13 : 08:26:22
[code]declare @Sample table(id int, txt varchar(30))
insert @Sample
select 1, 'A' union all
select 1, 'B' union all
select 2, 'C' union all
select 3, 'D'

select * from @Sample


delete dt
from
(select row_number() over (partition by id order by txt) as rn,* from @Sample)dt
where rn > 1

select * from @Sample
[/code]


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

dattatreysindol
Starting Member

20 Posts

Posted - 2012-06-13 : 08:49:17
Hi Joshrinn,

Please take a look at the following article for various different ways to delete duplicate rows from a table.

[url]http://www.mssqltips.com/sqlservertip/1918/different-strategies-for-removing-duplicate-records-in-sql-server/[/url]


Dattatrey Sindol (Datta)
http://dattatreysindol.com/

This information is provided "AS IS" with no warranties, and confers no rights.
Go to Top of Page

jimoomba
Yak Posting Veteran

90 Posts

Posted - 2012-06-13 : 09:11:29
Hi,

You can find the solution from the below link:
http://blog.sqlauthority.com/2009/06/23/sql-server-2005-2008-delete-duplicate-rows/

Let me know if you have any doubts.
Thanks,
Ram

rams
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-06-13 : 10:20:44
quote:
Originally posted by Joshrinn

How can I delete duplicate rows from my table. Can you please post the query with imaginary table name


what according to you're duplicates

first define that by means of sample data and show us what you want as output.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -