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 |
superjen26
Starting Member
1 Post |
Posted - 2011-09-08 : 20:30:24
|
Hi I need a little help in this queryI need to save one from each group of duplicate records that need to deleteex.there are 10 records that are duplicated and I need to eliminate 9 of them and save only 1 record..hoping for fast help, :)annyeong |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-09 : 08:22:49
|
do you have a unique valued column in your table like id column or datetime (timestamp) column?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
mayoorsubbu
Yak Posting Veteran
95 Posts |
Posted - 2011-09-15 : 10:44:29
|
Visakh I have a similar reqmt. I have a unique id col |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-15 : 11:38:14
|
just group by set of columns which identifies a duplicate set and the take MIN() or MAX() of uniquecol and join to main table.ie. if you table has duplicates based on columns col1 and col2 thenSELECT t.columns.....FROM Table tINNER JOIN (SELECT Col1,Col2,MAX(uniqueid) as Latest FROM Table GROUP BY Col1,Col2) t1ON t1.Col1= t.Col1AND t1.Col2 = t.Col2AND t1.Latest = t.uniqueid ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|