SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to delete
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Joshrinn
Posting Yak Master

118 Posts

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

webfred
Flowing Fount of Yak Knowledge

Germany
8514 Posts

Posted - 06/13/2012 :  08:26:22  Show Profile  Visit webfred's Homepage  Reply with Quote
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



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

India
20 Posts

Posted - 06/13/2012 :  08:49:17  Show Profile  Reply with Quote
Hi Joshrinn,

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

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


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

India
86 Posts

Posted - 06/13/2012 :  09:11:29  Show Profile  Reply with Quote
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

India
47099 Posts

Posted - 06/13/2012 :  10:20:44  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000