0

嗨,我有这样的 sql 代码:

SELECT vote_id, (SELECT type FROM vote_types WHERE id= 1) AS answer
FROM poll_answers
WHERE question_id =1;

它向我显示:

在此处输入图像描述

如何提出这个问题,以便它可以在第二行显示另一个 answer2 which vote_id = 2 而不再显示 answer1 ?

谢谢

4

2 回答 2

0

我不知道你的桌子。但我认为 - 查询应该是

SELECT vote_id, type as answer 
    FROM poll_answers, vote_types
    WHERE question_id =1 and question_id = id;
于 2012-05-09T09:53:29.280 回答
0
SELECT poll_questions.id, vote_types.type AS answer
FROM   poll_questions
  JOIN poll_answers ON poll_questions.id    = poll_answers.question_id
  JOIN vote_types   ON poll_answers.vote_id = vote_types.id
WHERE  poll_questions.referendum_id = 1
于 2012-05-09T17:21:52.850 回答