[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 302
  • Last Modified:

How can I do this in MSS-Access sql?

I have 2 table with a common key. tblPatient and tblMeds linked by chart. Is there a way in sql to get all the patients that have (for example) MedicationA, MedicationB and MedicationC? I want all the patients that take all 3 medications. Sounds simple but it dosn't seem to be. Thanks in advance.
0
DevLSS
Asked:
DevLSS
1 Solution
 
Jeffrey CoachmanCommented:
Then why not post what you tried, so we can look at it...?
0
 
aikimarkCommented:
sure.  with the query wizard, join the tblPatient and tblMeds tables.

Add the patient identifying field to the grid.
Add the med identifying field to the grid twice.
Click the summation toolbar button, converting this to a Group By query.
Change the first Med column type to Count.
Change the second Med column type to Where
In the criteria for the second Med column, type an In ( , , ) condition that will select all three meds you are interested in.

Test this query to make sure you've got the In() clause typed correctly.

Go back to design mode.
In the criteria area for the first Med column, type 3.

Run the query again.
0
 
GRayLCommented:
You have tblPatients and tblMeds.  You need a third table tblPatsMeds containing the Meds taken by each patient.  In this case, you want to know which patients in tblPatsMeds has a record for each of meds MedA, MedB, and MedC.

TRANSFORM First(PatID)
SELECT PatID
FROM tblPatsMeds
GROUP BY PatID
PIVOT MedID IN ("MedA","MedB","MedC")

Once you see that this works, you can get additional details like FName, LName, MedName by Joining to tblPatients and tblMeds.
0
 
DevLSSAuthor Commented:
Thanks, that does it!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now