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
SQL

Avatar of undefined
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;
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Qlemo

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
awking00

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.