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)
 Need to delete duplicate data

Author  Topic 

satish.gorijala
Posting Yak Master

182 Posts

Posted - 2009-11-13 : 00:05:59
Hi Team,
i have one table with 10 columns and 2 lakh records. i want to remove duplicate records(special case).

Here duplication in the sense, except two columns remaining 8 columns contain same data. So i need to remove the duplicates among them. let we see my data table here

Col1 Col2 Col3 Col4 Col5 Col6 Col7 Col8 Col9 Col10
TX abc 0 0 0 0 0 0 0 l
Tx def 0 0 0 0 0 0 0 k
Ag xyz 8 7 0 9 0 0 0 p
Ag jhk 8 7 0 9 0 0 0 m

Here First two rows are duplicates. We need to ignore columns Col2,col10. Remaining data are same for first 2 rows. So we need to delete one row from the table.
Similary last 2 rows data are same exceo for Col2 and Col10.
Like this my whol table contains data with 1 lakh records...i need to remove duplicates ignoring Col2 and Col10 columns. How can i do this? Can any one help me the query for this.

Thanks in advance


developer :)

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-11-13 : 00:09:02
[code]
delete d
from
(
select *, row_no = row_number() over (partition by Col1, Col3, Col4, Col5, Col6, Col7, Col8, Col9 order by Col2, Col10)
from yourtable
) d
where d.row_no > 1
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

satish.gorijala
Posting Yak Master

182 Posts

Posted - 2009-11-13 : 00:32:59
I am not getting accurate results by below query...
some thing is missing..i hope
quote:
Originally posted by khtan


delete d
from
(
select *, row_no = row_number() over (partition by Col1, Col3, Col4, Col5, Col6, Col7, Col8, Col9 order by Col2, Col10)
from yourtable
) d
where d.row_no > 1



KH
[spoiler]Time is always against us[/spoiler]





developer :)
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-11-13 : 00:39:47
example ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -