我正在查询“问题”并与“答案”一起加入。每个问题可能有两个或多个答案。因此,返回的问题数乘以答案数。这使我无法实现分页。我怎样才能避免这种情况?谢谢。
这是我的查询:
<cfquery name="questions">
SELECT
questions.id as questionid,
questions.question as question,
questions.rank as rank,
questions.isrequired as isrequired,
questiontypes.id AS questiontypeid,
questiontypes.name as questiontype,
questiontypes.template as template,
questions.survey_id as survey_id,
surveys.name as surveyname,
surveys.questionsperpage as questionsperpage,
surveys.thankyoumsg as thankyoumsg,
answers.id as answerid,
answers.answer as answer
FROM
questions
LEFT JOIN answers ON answers.question_id = questions.id
INNER JOIN questiontypes ON questions.questiontype_id = questiontypes.id
INNER JOIN surveys ON questions.survey_id = surveys.id
WHERE
questions.survey_id = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.surveyid#">
</cfquery>