PDA

View Full Version : multiple join / nested joins?


homerUK
04-25-2006, 12:16 PM
I have three tables:

QUESTIONS
questionID
surveyID

RESPONSES
responseID
surveyID

ANSWERS
answerID
questionNo
responseID

I need to query the answer table, and get the questionID for which they have answered. My problem is that for some reason when I designed the database, I didnt assign the answer to the questionId. Now I need to make an SQL query to get the questionID based on the question number.

My problems is that the SQL needs to be nested I think.

The answer has a responseID (ANSWERS TABLE)
the responseID has a surveyID (RESPONSES TABLE)
the surveyID can then get the questionID (QUESTIONS TABLE)

I've tried this


select
questions.questionID
FROM questions
right join (responses.surveyID on questions.surveyID)
ON questions.surveyID = responses.surveyID


but it's probably far from perfect - as it doesnt even work.
any ideas?!

thanks :)

vinyl-junkie
04-26-2006, 06:05 AM
I think you might be able to do this with inner joins. Tell me one thing though: Is questionID in your Questions table a foreign key to questionNo in the Answers table?