如何在 Oracle 中删除重复的记录,与不同的列?

标签: Oracle
发布时间: 2017/4/15 18:47:24
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

我有一个问题与删除重复数据行的不同列中︰

SELECT   p1, p2

  FROM   (SELECT   'A' AS p1, 'B' AS p2 FROM DUAL
          UNION
          SELECT   'B' AS p1, 'A' AS p2 FROM DUAL) a;

和,其结果将是︰

P1 P2 
— 
,B  
B,A  

我只是需要 A,B 或 B、 A

解决方法 1:

SELECT   distinct least(p1, p2), greatest(p1, p2)
  FROM   (SELECT   'A' AS p1, 'B' AS p2 FROM DUAL
          UNION
          SELECT   'B' AS p1, 'A' AS p2 FROM DUAL) a;
赞助商