WITH tt AS ( SELECT 1 id, 11 aa, null ab, null ac, 22 ad FROM dual UNION ALL SELECT 2, null, 11, null, 23 FROM dual UNION ALL SELECT 3, 33, null, null, 11 FROM dual ) SELECT * FROM (SELECT gb, v , ROW_NUMBER() OVER(PARTITION BY gb ORDER BY id) rn FROM tt UNPIVOT (v FOR gb IN (aa, ab, ac, ad)) ) PIVOT (MIN(v) FOR gb IN ('AA' aa, 'AB' ab, 'AC' ac, 'AD' ad)) ;