tags:

views:

836

answers:

2

I have this very simple sql statement:

SELECT     max_dose
FROM         psychotropes
WHERE     (patient_meds.psychotrope = psychotrope_name) AND (patient_meds.patient_id = 12)

when I try to run it in Visual Studio 2008, it tells me "The multi-part 'patient_meds.psychotrope' identifier could not be bound"

it's weird, because I did set a relationship between the two tables in the diagram viewer

+1  A: 

I guess you'll have to include patient_meds in the table list as:

FROM psychotropes, patient_meds
codaddict
omg. I can't believe I made this mistake. well, it has been months I didn't touch joins... thx man
jello
This is an old style join... bad form. See durilai's answer for JOIN keyword use
gbn
+3  A: 

You are not including the table in the query. Without knowing the schema this is just an assumption. Also a database diagram does nothing to assist in queries.

SELECT ax_dose
FROM psychotropes
INNER JOIN patient_meds ON psychotropes.psychotrope_name = patient_meds.psychotrope
WHERE (patient_meds.patient_id = 12)
Dustin Laine
"Also a database diagram does nothing to assist in queries" you mean I don't need to link two tables together with a foreign key to join them?
jello
@jello: Technically, in most RDBMSs, no. It's still a good idea to, though.
Michael Petrotta
@durilai: An ERD saves having to run multiple `DESC table` commands to get the same info.
OMG Ponies
@OMG, I understand the benefits. My thoughts were that he was assuming that since he had defined a foreign key he did not have to manually join the table. @Michael, Agree. FK constraints should be included where appropriate.
Dustin Laine