1

Here is the code I'm running into an error with:

FROM
    IndexPID
    INNER JOIN Demographics ON
        IndexPID.NDoc_Number = Demographics.NDoc_Number,
    PatientSupply
    INNER JOIN Demographics ON
        PatientSupply.NDocNum = Demographics.NDoc_Number

I also tried it this way:

FROM
    IndexPID, PatientSupply
    INNER JOIN Demographics ON
        IndexPID.NDoc_Number = Demographics.NDoc_Number
    INNER JOIN Demographics ON
        PatientSupply.NDocNum = Demographics.NDoc_Number

But no cigar. Anybody tell me what I'm doing wrong?

2
  • IndexPID, Demographics and Patient Supply are tables. I need to join Demographics to IndexPID and Patient Supply on their NDoc_Number fields Commented Aug 20, 2012 at 20:22
  • 3
    The error is because you're just randomly throwing the name "PatientSupply" in random places. If it's a table name, it needs to be joined. Commented Aug 20, 2012 at 20:22

4 Answers 4

4

You were very close:

FROM IndexPID
INNER JOIN Demographics 
   ON IndexPID.NDoc_Number = Demographics.NDoc_Number
INNER JOIN PatientSupply
   ON Demographics.NDoc_Number = PatientSupply.NDocNum
Sign up to request clarification or add additional context in comments.

Comments

4

would be easier if you posted the whole SQL!

Try

FROM
IndexPID
INNER JOIN Demographics ON
    IndexPID.NDoc_Number = Demographics.NDoc_Number
INNER JOIN PatientSupply ON
    PatientSupply.NDocNum = Demographics.NDoc_Number

Comments

2

You are mixing implicit (comma-separated) and explicit JOINs in an odd way here. It should look like the following, using explicit INNER JOINs only, with no commas between table names or ON clauses:

FROM
  IndexPID
  INNER JOIN Demographics 
    ON IndexPID.Ndoc_Number = Demographics.NDoc_Number
  INNER JOIN PatientSupply 
    ON PatientSupply.NDocNum = Demographics.NDoc_Number

Comments

1

You uses inner join so you can use:

FROM Demographics
inner join IndexPID on Demographics.NDoc_Number=IndexPID.NDoc_Number
inner join PatientSupply on Demographics.NDoc_Number=PatientSupply.NDocNum

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.