从SQL Server 2000中的不同列中删除重复项

时间:2010-04-09 06:43:42

标签: sql-server sql-server-2000

我有桌子:

number city1 city2 mentions
1 a b 5
1 b a 5
1 c d 2
1 d c 2

我需要的是删除重复记录,例如a,b等于b,a成为:

number city1 city2 mentions
1 a b 5
1 c d 2

对我来说有什么线索?

之前感谢:)

1 个答案:

答案 0 :(得分:1)

喜欢这个吗?

delete from table t1
where exists (
  select *
  from table t2
  where
    t2.number = t1.number and
    t2.city1 = t1.city2 and
    t2.city2 = t1.city1 and
    t2.mentions = t1.mentions and
    t2.city1 < t2.city2
)