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 |
rukkur
Starting Member
10 Posts |
Posted - 2004-09-21 : 06:51:26
|
How to get duplicate rows from 1 table(name,sal) |
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2004-09-21 : 06:55:59
|
select name, count(sal)from table1group by namehaving count(sal) > 1Duane. |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-09-21 : 07:01:20
|
this should help:select * from MyTable t1where 1<(select count(id) from MyTable where t1.id = id)Go with the flow & have fun! Else fight the flow |
|
|
rukkur
Starting Member
10 Posts |
Posted - 2004-09-21 : 07:06:07
|
I want to Identify and Delete all duplicate records (only 1 record should remain) |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-09-21 : 07:31:49
|
aha... then the easiest way is to do #temp table should have same structure as MyTableinsert into #temp(col1 , ...)select (select col1 , ...from MyTable )union(select col1 , ...from MyTable )delete from MyTableinsert into MyTable(col1 , ...)select col1 , ...from #tempthe union operator creates distinct records.you could also do:select distinct * into #tempfrom MyTableand then delete the data from MyTable and insert the data from #temp back in.Go with the flow & have fun! Else fight the flow |
|
|
rukkur
Starting Member
10 Posts |
Posted - 2004-09-21 : 07:52:22
|
Thanks , is there any way to do in single query? |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
|
|
|
|