WITH T ( A , B, C, D, E , F ) AS ( SELECT 'A' , 'B' ,'C' ,'D' ,'E' ,'G' FROM DUAL UNION ALL SELECT 'A' , 'B' ,'C' ,'D' ,'B' ,'F' FROM DUAL UNION ALL SELECT 'A' , 'B' ,'C' ,'D' ,'G' ,'G' FROM DUAL UNION ALL SELECT 'A' , 'B' ,'C' ,'D' ,'A' ,'Z' FROM DUAL UNION ALL SELECT 'B' , 'C' ,'D' ,'E' ,'B' ,'E' FROM DUAL UNION ALL SELECT 'B' , 'C' ,'D' ,'E' ,'Z' ,'G' FROM DUAL UNION ALL SELECT 'B' , 'C' ,'D' ,'E' ,'E' ,'D' FROM DUAL ) SELECT CASE WHEN RN = 1 THEN A END A , CASE WHEN RN = 1 THEN B END B , CASE WHEN RN = 1 THEN C END C , CASE WHEN RN = 1 THEN D END D , E , F FROM (SELECT T.* , ROW_NUMBER() OVER(PARTITION BY A,B,C,D ORDER BY ROWNUM ) RN FROM T )