Hello,
I was trying to understand the mechanism of multiple left joins in SQL.
I wonder how it works? I assume each left join creates an intermediate table and that combines with subequent table. In my example dat1and dat2 yields an intermediate table and it joins with dat3.
Is the total number of observations (records) in multiple left joins equal to the number of observations in first left join?
data dat1;
input id $ x;
cards;
a 1
b 2
c 3
;
run;
data dat2;
input id $ y;
cards;
a 1
;
run;
data dat3;
input id $ z;
cards;
b 2
;
run;
proc sql;
create table t1 as
select a.*,b.*,c.*
from dat1 as a
left join dat2 as b
on a.id = b.id
left join dat3 as c
on a.id = c.id;
quit;
I wonder how it works? I assume each left join creates an intermediate table and that combines with subsequent table. In my example dat1and dat2 yields an intermediate table and it joins with dat3.
True. Unless you alter join operations order with parentheses.
Is the total number of observations (records) in multiple left joins equal to the number of observations in first left join?
Not necessarily, if there are multiple matches on the right side, there can be more records in the joined table than there were in the left table.
I wonder how it works? I assume each left join creates an intermediate table and that combines with subsequent table. In my example dat1and dat2 yields an intermediate table and it joins with dat3.
True. Unless you alter join operations order with parentheses.
Is the total number of observations (records) in multiple left joins equal to the number of observations in first left join?
Not necessarily, if there are multiple matches on the right side, there can be more records in the joined table than there were in the left table.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.