Link to home
Start Free TrialLog in
Avatar of Jamil Muammar
Jamil Muammar

asked on

Way to Join only the first record

Dear Experts,

 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
Avatar of ste5an
ste5an
Flag of Germany image

Further constraints?

Otherwise just use a sub-query as source for the left joined table, which return a single row.
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.
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.
ASKER CERTIFIED SOLUTION
Avatar of awking00
awking00
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial