How Do I in Oracle SQL make Left join between two tables which take only the first record in the right join?
For Example
Table 1:
A 100
B 200
C 300
Table:2
A 900
A 300
The Result will be
A 100 900
B 200 null
C 300 null
Thanks
SQL
Last Comment
awking00
8/22/2022 - Mon
ste5an
Further constraints?
Otherwise just use a sub-query as source for the left joined table, which return a single row.
Qlemo
What determines the "first" row - maximum value maybe?
I agree you should set up a subquery as table source, which delivers only those rows you want to have joined. As soon as you are able to write up that query, the remainder is easy.
awking00
This can work for your example, but be careful since any inserts and/or deletes can radically change the results
select t1.col1 as t1_value, t2.col1 as t2_value from
(select col1, rownum rn from table1) t1
left join
(select col1, rownum rn from table2
where rownum = 1) t2
on t1.rn = t2.rn;
awking00, that can't work, because the row numbers of each table have no connection to each other, and rownum is the row number of the select, not the table.
Otherwise just use a sub-query as source for the left joined table, which return a single row.