WITH x AS( SELECT 1 id FROM dual UNION SELECT 2 FROM dual UNION SELECT 3 FROM dual ), y AS( SELECT 1 id, 1 nr, 'B' code FROM dual UNION SELECT 1, 2, 'A' FROM dual UNION SELECT 2, 2, 'A' FROM dual ) -- end of test data SELECT * FROM ( SELECT x.id, y.nr, y.code, ROW_NUMBER() OVER (PARTITION BY x.id ORDER BY y.nr) AS rn FROM x LEFT OUTER JOIN y ON y.id = x.id ) WHERE rn = 1