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

javascript - Iterate over array and calculate average values of array-parts -

iphone - Using nested NSDictionary with Picker -

objective c - Newbie question -multiple parameters -