SQL Server :Remove duplicate records but be able to choose which record to keep by specific column -


i have problem , can't find right solution. hope can me.

i have table looks this:

id  date      description     location 1  2012-12-01   low              1  2012-12-01   low              1  2012-12-01   low              b 2  2012-12-01   high             3  2012-12-01   low              c 

the result should this

id  date      description     location 1  2012-12-01   low              b 2  2012-12-01   high             3  2012-12-01   low              c 

i hope me.

a general method prioritize rows use row_number() case statement.

in case, seem be:

select t.* (select t.*,              row_number() on (partition id, description                                 order location desc                                ) seqnum       table t      ) t seqnum = 1; 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -