How to make a join between two tables, but restricting the first row that matches the join condition?
In this simple example, I would like to get for each row of table_A the first row from table_B that satisfies the condition:
select table_A.id, table_A.name, table_B.city from table_A join table_B on table_A.id = table_B.id2 where .. table_A (id, name) 1, John 2, Marc table_B (id2, city) 1, New York 1, Toronto 2, Boston The output would be: 1, John, New York 2, Marc, Boston
Maybe Oracle provides such a feature (performance is a problem).
sql join oracle greatest-n-per-group
kkung
source share