Link to home
Start Free TrialLog in
Avatar of wjstarck
wjstarck

asked on

Join three tables mySQL

I want to join three tables: anestheticrecord, patient and anesthmedsgiven

anestheticrecord and patient share the field 'PatNum'
anestheticrecord and anesthmedsgiven share the field 'AnestheticRecordNum'

I've tried the following:

SELECT anestheticrecord.AnestheticRecordNum,anestheticrecord.AnestheticDate,
patient.PatNum as 'Patient #',patient.LName,patient.FName,patient.Gender,patient.Birthdate,patient.Address,patient.Address2,patient.City,patient.Zip,
patient.HmPhone,patient.WirelessPhone,anesthmedsgiven.AnesthMedName,anesthmedsgiven.QtyGiven,anesthmedsgiven.QtyWasted
FROM anestheticrecord,patient,anesthmedsgiven
WHERE ((anestheticrecord.PatNum = patient.PatNum) AND (anesthmedsgiven.AnestheticRecordNum = anestheticrecord.AnestheticRecordNum))
AND DATE_FORMAT(anestheticdate,'%Y-%m-%d') >= '2011-01-01' AND DATE_FORMAT(anestheticdate,'%Y-%m-%d') <= '2011-03-11'

which returns no results. I don't think I can use 2 LEFT JOINS because the three tables don't share a foreign key.

Any suggestions?
ASKER CERTIFIED SOLUTION
Avatar of DrivingInstructor
DrivingInstructor

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of wjstarck
wjstarck

ASKER

Yes, that does work after all. Thanks.