如何在SQL中删除重复的行 [英] How to remove duplicate rows in SQL
本文介绍了如何在SQL中删除重复的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要删除以下数据中的重复行.
I want to remove duplicate rows in the following data.
数据:
a a
a b
a c
a d
a e
b a
b b
b c
b d
b e
c a
c b
c c
c d
c e
d a
d b
d c
d d
d e
e a
e b
e c
e d
e e
输出应与column1和column2不同. 且不应为以下数据.
The output should be column1 and column2 different. and it should not be the following data.
a b
a c
a d
a e
b a
b c
b d
b e
c a
c b
c d
c e
d a
d b
d c
d e
e a
e b
e c
e d
因为第1列中的a和第2列中的b与第1列中的b和第2列中的a相同,否则我只是说1 + 2与2 + 1相同.
because a in column 1 and b in column2 is same as b in column1 and a in column2 or else simply i mean to say 1+2 is same as 2+1.
因此,输出应为
a,b
a,c
a,d
a,e
b,c
b,d
b,e
c,d
c,e
d,e
推荐答案
select distinct least(column_1, column_2), greatest(column_1, column_2)
from the_table
where column_1 <> column_2;
这篇关于如何在SQL中删除重复的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文