2010-04-09 100 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 
)