WITH t AS ( SELECT 'A1' c1, 'B1' c2 FROM dual UNION ALL SELECT 'A2', 'B1' FROM dual UNION ALL SELECT 'A2', 'B2' FROM dual UNION ALL SELECT 'A2', 'B3' FROM dual UNION ALL SELECT 'A2', 'B5' FROM dual UNION ALL SELECT 'A3', 'B5' FROM dual UNION ALL SELECT 'A3', 'B7' FROM dual UNION ALL SELECT 'A4', 'B8' FROM dual UNION ALL SELECT 'A4', 'B9' FROM dual UNION ALL SELECT 'A5', 'B7' FROM dual UNION ALL SELECT 'A6', 'B8' FROM dual ) SELECT DISTINCT c1, c2 FROM t START WITH c2 = 'B5' CONNECT BY NOCYCLE PRIOR c1 = c1 OR PRIOR c2 = c2 ORDER BY c1, c2 ;