BookmarkSubscribeRSS Feed
mrdlau
Obsidian | Level 7
Suppose i have 3 tables:
My query is essentially
Select *
From T1
Inner join T2 on T1
Inner join T3 on T2
Where T1.filter = somefilter.

I understand T2 will join into the filtered T1 because of the where statement. Does T3 join on the newly filtered T2(because of T1), or will it try to join T2 as if it is unfiltered

5 REPLIES 5
PGStats
Opal | Level 21

Your ON join-conditions are not syntactically correct. They should read ON T1.something1 = T2.something2

PG
mrdlau
Obsidian | Level 7
Thanks. I know my joints aren’t correct from a syntax perspective. I was just asking from a conceptual perspective. I.e. can I join 1 and 2 and then 3 and 2 in one join
ChrisNZ
Tourmaline | Level 20

@mrdlau   > can I join 1 and 2 and then 3 and 2 in one join
Yes you can.  And any other combination.

 

Why even ask? As @kiranv_ said, just try it.

You'll have the answer faster, and you'll learn better.

kiranv_
Rhodochrosite | Level 12

best way to understand by  making up data and try out various scenarios. This will tremendously increase your knowledge. check with on clause initially then try where clauses. Nothing better than learning by doing.

Kurt_Bremser
Super User

And while you're doing your tests, as @kiranv_ suggested, also try a solution with sort and data steps, where you do the joins piecemeal.

With larger datasets, the overall performance might surprise you.

Caveat: This is only possible with 1-to-many, not with many-to-many relationships, where SQL is needed for the cartesian join.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 853 views
  • 2 likes
  • 5 in conversation