Avatar of al4629740
al4629740
Flag for United States of America asked on

JOIN query between 3 tables

Attached is an image of my DB and relations between the tables.  I would like to query all the records in tblOrgHours where the  MONTH(tblOrgHours.ActivityDate) = 5.  I would like to also have the ActivityName of each associated ActivityID.  Also the [First Name] and [Last Name] of the each associated RegID  

How do I formulate an sql statement to get all these values in one query?
dbs-structure.jpg
Microsoft SQL Server

Avatar of undefined
Last Comment
PortletPaul

8/22/2022 - Mon
SOLUTION
Jason Schlueter

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
al4629740

ASKER
with acitivityname it would be

SELECT tor.[First Name],
       tor.[Last Name],
       tor.birthdate,
       tor.regid,
       tor.agencyid,
       toh.activityid,
         toa.[activity name]
FROM   tblorgregistrations tor
       JOIN tblorghours toh
         ON tor.regid = toh.regid
       JOIN tblorgactivities toa
         ON toa.activityid = toh.activityid
WHERE  Month(toh.activitydate) = 5
al4629740

ASKER
What the difference between what you gave me and this:

select max(r.[Last Name])LastName, max(r.[First Name])FirstName, max(r.BirthDate)Birthdate,max(H.Hours)Hours, max(ActivityDate)ActivityDate 
from tblOrgRegistrations R
left Join tblOrgHours H on R.RegID = H.RegID
left Join tblOrgActivities A on A.ActivityID = H.ActivityID where  Month(H.activitydate) = 5 group by ActivityDate, [Last Name],[First Name],BirthDate,h.Hours

Open in new window

ASKER CERTIFIED SOLUTION
PortletPaul

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23