I'm working on a .NET project and I need a single query to return a
result set from three related tables in Access 2003, and I'm having
trouble getting the results I want.
The details:
Question ------------
QuestionID
QuestionText
Question_MediaTypeID
etc.
Answer --------------
AnswerID
Answer_QuestionID
AnswerOptionText
etc.
AnswerMarket -----------
AMID
AM_MediaTypeID
AMmediaContent
etc.
The Question and Answer table are joined by the QuestionID and
Answer_QuestionID columns.
The Question and AnswerMarket tables are joined by the
Question_MediaTypeID and AM_MediaTypeID (they are both referring to
another table named MediaType, which describes whether we're talking
about newspapers, websites, or radio).
I need to pull back ONE specific record from the Question table (based
on the QuestionOrder parameter passed through a URL). No problem.
I need to pull back the THREE associated records in the Answer table:
SELECT *
FROM Question, Answer
WHERE QuestionOrder = @QuestionOrder AND
QuestionID = Answer_QuestionID
Works like a charm.
Now, there are EIGHTEEN rows in the AnswerMarket table. And, of
course, when I run this query I get 54 rows returned (3 x 18 = 54):
SELECT *
FROM Question, Answer, AnswerMarket_Chicago
WHERE
QuestionOrder = @QuestionOrder AND
QuestionID = Answer_QuestionID AND
Question_MediaTypeID = AM_MediaTypeID
I've tried a few techniques (including subqueries and different join
types), but I'm not getting the results I need.
Any suggestions and guidance (icluding best practices for this type of
situation) would be greatly appreciated.