2010-04-09 126 views
1

我有表:删除重复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 

我的任何线索?

感谢之前:)

+2

请缩进你的question.use ctrl-K。 – Salil 2010-04-09 06:46:58

+0

您可以使用“代码示例”功能来格式化表格内容吗? – systempuntoout 2010-04-09 06:47:32

回答

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 
)