sql - TSQL Remove duplicated rows on some column only -


possible duplicate:
sql - how can remove duplicate rows?

example table:

sitekey, name, city

the sitekey auto increament, name different , times 2 sitekey have same city.

example:

1, , citya 2, b,  cityb 3, c,  citya 4, d,  cityf 

so need remove rows 3, , keep rows 1,2,4 only.

its on sql 2005 , up.

thanks help.

here 2 ways can it.

delete t  <table> t exists      (select 1 <table>      t.sitekey > sitekey , t.city = city)   delete t  <table> t inner join <table> t2 on  t.city = t2.city , t.sitekey > sitekey 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -