WITH t AS ( SELECT 1 id, 'A' q, 5 a FROM dual UNION ALL SELECT 1, 'B', 6 FROM dual UNION ALL SELECT 1, 'C', 7 FROM dual UNION ALL SELECT 1, 'D', 1 FROM dual UNION ALL SELECT 1, 'E', 5 FROM dual UNION ALL SELECT 1, 'F', 9 FROM dual UNION ALL SELECT 1, 'G', 8 FROM dual UNION ALL SELECT 1, 'H', 2 FROM dual UNION ALL SELECT 1, 'I', 1 FROM dual UNION ALL SELECT 1, 'J', 2 FROM dual UNION ALL SELECT 2, 'A', 8 FROM dual UNION ALL SELECT 2, 'B', 2 FROM dual UNION ALL SELECT 2, 'C', 3 FROM dual UNION ALL SELECT 2, 'D', 2 FROM dual UNION ALL SELECT 2, 'E', 1 FROM dual UNION ALL SELECT 2, 'F', 8 FROM dual UNION ALL SELECT 2, 'G', 2 FROM dual UNION ALL SELECT 2, 'H', 9 FROM dual UNION ALL SELECT 2, 'I', 1 FROM dual UNION ALL SELECT 2, 'J', 5 FROM dual UNION ALL SELECT 3, 'A', 8 FROM dual UNION ALL SELECT 3, 'B', 7 FROM dual UNION ALL SELECT 3, 'C', 1 FROM dual UNION ALL SELECT 3, 'D', 9 FROM dual UNION ALL SELECT 3, 'E', 3 FROM dual UNION ALL SELECT 3, 'F', 7 FROM dual UNION ALL SELECT 3, 'G', 5 FROM dual UNION ALL SELECT 3, 'H', 8 FROM dual UNION ALL SELECT 3, 'I', 6 FROM dual UNION ALL SELECT 3, 'J', 1 FROM dual ) -- 1. Group By ~ Min(Decode()) SELECT id , MIN(DECODE(q, 'A', a)) a , MIN(DECODE(q, 'B', a)) b , MIN(DECODE(q, 'C', a)) c FROM t WHERE q IN ('A', 'B', 'C') GROUP BY id ; -- 2. PIVOT SELECT * FROM t PIVOT (MIN(a) FOR q IN ('A' a, 'B' b, 'C' c)) ;