我有2个查询,我想将其变成一个。
第一
SELECT
poll_questions.id,
poll_questions.question,
poll_questions.qmore,
poll_questions.total_votes,
poll_questions.active,
poll_questions.created_at,
poll_answers.answer,
poll_answers.votes,
poll_answers.id AS answer_id,
poll_photos.photo_name_a,
users.username
FROM poll_questions
LEFT JOIN (poll_answers, poll_photos)
ON (poll_answers.question_id = poll_questions.id AND
poll_photos.question_id = poll_questions.id
)
LEFT JOIN users ON poll_questions.author = users.id
WHERE poll_questions.active = 1
ORDER BY poll_questions.created_at DESC
LIMIT {$per_page} OFFSET {$offset}
第二
SELECT vote_history_raw.vote
FROM vote_history_raw
WHERE vote_history_raw.user_id = {$user_id}
请注意,第一个查询中的用户是作者,第二个查询中的用户是选民。
感谢您的帮助!