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.Anestheti cRecordNum ,anestheti crecord.An estheticDa te,
patient.PatNum as 'Patient #',patient.LName,patient.F Name,patie nt.Gender, patient.Bi rthdate,pa tient.Addr ess,patien t.Address2 ,patient.C ity,patien t.Zip,
patient.HmPhone,patient.Wi relessPhon e,anesthme dsgiven.An esthMedNam e,anesthme dsgiven.Qt yGiven,ane sthmedsgiv en.QtyWast ed
FROM anestheticrecord,patient,a nesthmedsg iven
WHERE ((anestheticrecord.PatNum = patient.PatNum) AND (anesthmedsgiven.Anestheti cRecordNum = anestheticrecord.Anestheti cRecordNum ))
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?
anestheticrecord and patient share the field 'PatNum'
anestheticrecord and anesthmedsgiven share the field 'AnestheticRecordNum'
I've tried the following:
SELECT anestheticrecord.Anestheti
patient.PatNum as 'Patient #',patient.LName,patient.F
patient.HmPhone,patient.Wi
FROM anestheticrecord,patient,a
WHERE ((anestheticrecord.PatNum = patient.PatNum) AND (anesthmedsgiven.Anestheti
AND DATE_FORMAT(anestheticdate
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER