如何删除Oracle中具有不同列的重复记录?

时间:2013-01-16 09:35:31

标签: database oracle

我在删除具有不同列的行中的重复数据时遇到问题:

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 
-- -- 
A , B  
B , A  

我只需要A,B或B,A

1 个答案:

答案 0 :(得分:0)

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;