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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 681 views
  • 2 likes
  • 5 in conversation