11

When running the below query I get an error saying

"Syntax error (missing operator) in query expression 'diagnosis.Patient_No = 'Patient_No INNER JOIN Illness ON Illness.Illness_Code = Diagnosis.Illness_Code'

SELECT Patient.Last_Name AS LastName,
       Patient.First_Name AS FirstName,
       Patient.Gender AS Gender,
       Patient.Age AS Age,
       Illness.Illness_Desc AS illness,
       Medication.Medication_Desc AS Medication,
       Prescription.Dosage AS Dosage
FROM Patient
INNER JOIN Diagnosis ON Patient.Patient_No = Diagnosis.Patient_No
INNER JOIN Illness ON Diagnosis.Illness_Code = Illness.Illness_Code
INNER JOIN Prescription ON Patient.Patient_No = Prescription.Patient_No
INNER JOIN Medication ON Prescription.Medication_code = Medication.Medication_code

I confirmed that illness_code are both in Illness and Diagnosis tables and everything should work? Not sure if during this join I need to add these illness codes to the select statement? I tried adding them to my Select and that didnt seem to work for me either.

4 Answers 4

7
Medication.Medication_Desc AS Medication,
Prescription.Dosage AS Dosage

Looks like you don't have the medication and prescription tables joined in your FROM statement.

5

You didn't specify the table for the second Patient_No column in the first join. It should be

INNER JOIN Diagnosis ON Diagnosis.Patient_No = Patient.Patient_No

You are also selecting columns from two tables that you aren't joining on - Medication and Prescription. However, this should give you a different error of "The multi-part identifier 'Medication.Medication_Desc' could not be bound."

The specific error you are getting sounds like the first problem I mentioned. Here's a working SQL filter with the Medication / Prescription tables omitted.

SQL Fiddle

3
  • I changed it to Patient.Patient_No and it didnt make a difference. Seriously stumped.
    – Zi0n1
    Feb 8, 2013 at 2:42
  • I updated my above code to reflect adding all of the INNER JOINS. Still not working properly. Am I using the JOIN incorrectly?
    – Zi0n1
    Feb 8, 2013 at 2:55
  • Here's an updated fiddle. It has your exact SQL with some empty tables. No data is returned, but it executes, so I think the problem lies elsewhere. - sqlfiddle.com/#!6/d288f/1 Feb 8, 2013 at 3:03
0

Also add INNER JOINS for the other two tables,

INNER JOIN Medication ON Medication.<> = Patient.<>

INNER JOIN Prescription ON Prescription.<> = Patient.<>
0

You can't still be getting the same error.. .What is happening now? try the below

 Select p.Last_Name LastName,
   p.First_Name FirstName,
   p.Gender Gender, p.Age Age,
   i.Illness_Desc illness,
   m.Medication_Desc Medication,
   s.Dosage Dosage
From Patient p
    Join Diagnosis d    On d.Patient_No = p.Patient_No
    Join Illness i      On i.Illness_Code = d.Illness_Code
    Join Prescription s On s.Patient_No = p.Patient_No
    Join Medication m   On m.Medication_code = p.Medication_code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.