13,093,097 members (65,410 online)
Rate this:
See more:
hi

I want to cut all duplicated rows on datatable and copy to an other datatable like this:

datatablefirst:
ID Name
123 Joe
123 John
124 Thro
125 Obama
126 Jenifer
127 Jack
127 Arnent
127 Joseph
129 Mali

Datatablenonduplicate:
ID Name
124 Thro
125 Obama
126 Jenifer
129 Mali

Datatableduplicate:
ID Name
123 Joe
123 John
127 Jack
127 Arnent
127 Joseph
Posted 20-Sep-11 3:28am

Rate this:

Rate this:

## Solution 2

You can do something like this.
use linq query to retrieve duplicates as shown below.
And loop through duplicate rows and add rows into duplicate table.
Finally remove duplicates from existing table to get unique rows.

```DataTable table=new DataTable();
//DataTable Datatablenonduplicate = table.Clone();
DataTable Datatableduplicate = table.Clone();
var dupsFromCol = from dr in table.AsEnumerable()
group dr by dr["ID"] into groups
where groups.Count() > 1
select groups;
foreach(var duplicate in dupsFromCol)
{
for(int i=0;i<duplicate.count();i++)>
{
DataRow dr = Datatableduplicate.NewRow();
dr=duplicate.ElementAt(i);
Datatableduplicate.ImportRow(dr);
table.Rows.Remove(dr);
}
}
```

table will contain unique rows and datatableduplicate contain duplicates rows.
Rate this:

## Solution 4

```with cte
as
(select id,count(id)'Countid' from EMP_TEST1 group by id
)

select E.ID,E.DEPT,E.GrossSalary,E.NAME,E.NetSalary,E.SCM into New_Table from cte c inner join EMP_TEST1 E on E.ID=c.ID where c.Countid>1;

with cte1
as
(select id,count(id)'Countid' from EMP_TEST1 group by id
)
select E.ID,E.DEPT,E.GrossSalary,E.NAME,E.NetSalary,E.SCM into New_Table1 from cte1 c inner join EMP_TEST1 E on E.ID=c.ID where c.Countid=1;

select * from New_Table
select * from New_Table1```

Top Experts
Last 24hrsThis month
 OriginalGriff 299 Graeme_Grant 198 Richard Deeming 150 RickZeeland 130 ProgramFOX 130
 OriginalGriff 3,911 Graeme_Grant 2,152 ProgramFOX 2,017 ppolymorphe 1,666 Jochen Arndt 1,645