sql server 2008 - remove duplicates from a row and keep the order sql -


i have table follows

seriesvariables_id     seriesvariables_label     seriesvariables_value    series_id 143                    batch number              test20passall            28 144                    serialno                  simtest                  28 145                    seg pull date             20/1/2014                28 146                    seg pull time             101010                   28 147                    batch number              test20passall            28 148                    serialno                  simtest                  28 149                    seg pull date             20/1/2014                28 150                    seg pull time             101010                   28 151                    batch number              test20passall            7 152                    serialno                  simtest2                 7 153                    seg pull date             20/2/2014                7 154                    seg pull time             202020                   7 

what keep order of table , remove duplicates. result this

seriesvariables_id     seriesvariables_label     seriesvariables_value    series_id 143                    batch number              test20passall            28 144                    serialno                  simtest                  28 145                    seg pull date             20/1/2014                28 146                    seg pull time             101010                   28 151                    batch number              test20passall            7 152                    serialno                  simtest2                 7 153                    seg pull date             20/2/2014                7 154                    seg pull time             202020                   7 

any appreciated!

if running sql, i've found answer @ https://stackoverflow.com/a/18949/1781207 helpful these situations. keep lowest seriesvariables_id want.

for example, in code should (where "mytable" name of table)

delete mytable  mytable left outer join (    select min(seriesvariables_id) rowid, seriesvariables_label, seriesvariables_value, series_id    mytable     group seriesvariables_label, seriesvariables_value, series_id ) keeprows on    mytable.seriesvariables_id = keeprows.rowid    keeprows.rowid null 

you can test see selected rows running inner select statement alone

select min(seriesvariables_id) rowid, seriesvariables_label, seriesvariables_value, series_id mytable group seriesvariables_label, seriesvariables_value, series_id 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -