为什么它在两行中显示相同的结果?

时间:2012-05-09 09:49:12

标签: mysql

嗨我有这样的SQL代码:

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

它显示我:

enter image description here

如何提出这个问题所以它可以显示另一个答案2,其中第二行中的vote_id = 2并且不再显示answer1?

感谢

2 个答案:

答案 0 :(得分:0)

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

SELECT vote_id, type as answer 
    FROM poll_answers, vote_types
    WHERE question_id =1 and question_id = id;

答案 1 :(得分: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