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.
| 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 hereCol1 Col2 Col3 Col4 Col5 Col6 Col7 Col8 Col9 Col10TX abc 0 0 0 0 0 0 0 lTx def 0 0 0 0 0 0 0 kAg xyz 8 7 0 9 0 0 0 pAg 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 advancedeveloper :) |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-11-13 : 00:09:02
|
[code]delete dfrom ( select *, row_no = row_number() over (partition by Col1, Col3, Col4, Col5, Col6, Col7, Col8, Col9 order by Col2, Col10) from yourtable) dwhere d.row_no > 1[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
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 hopequote: Originally posted by khtan
delete dfrom ( select *, row_no = row_number() over (partition by Col1, Col3, Col4, Col5, Col6, Col7, Col8, Col9 order by Col2, Col10) from yourtable) dwhere d.row_no > 1 KH[spoiler]Time is always against us[/spoiler]
developer :) |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-11-13 : 00:39:47
|
example ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|
|
|