繁体   English   中英

Mysql:仅联接表左表的第一行

[英]Mysql: Join Table Only First row on left table

查询是

SELECT * FROM Question 
INNER JOIN Question_Answer 
  ON Question.question_id = Question_Answer.question_id 
WHERE Question.question_group_id = 518

问题表包含以下列:

question_id|question_name|question_type|question_group_id|question_ask
1          |100-105      | gr           | 518                | question1
2          |100-105      | gr           | 518                | question2
3          |100-105      | gr           | 518                | question3
4          |100-105      | gr           | 518                | question4

Question_Answer包含以下列:

question_id|question_answer_text|question_answer_id|question_answer_is_correct
518           |Text1                    |1107                  |1
518           |Text2                    |1108                  |1
518           |Text3                    |1109                  |1
518           |Text4                    |1110                  |1

问题是它输出如下内容:

question_id|question_name|question_type|question_group_id|question_ask|question_id|question_answer_text|question_answer_id|question_answer_is_correct

1          |100-105      | gr           | 518                | question1 | 518           |Text1                    |1107                  |1
1          |100-105      | gr           | 518                | question1 | 518           |Text2                    |1108                  |1
1          |100-105      | gr           | 518                | question1 | 518           |Text3                    |1109                  |1
1          |100-105      | gr           | 518                | question1 | 518           |Text4                    |1110                  |1

我要实现的是:

1          |100-105      | gr           | 518                | question1 | 518           |Text1                    |1107                  |1
2          |100-105      | gr           | 518                | question2 | 518           |Text2                    |1108                  |1
3          |100-105      | gr           | 518                | question3 | 518           |Text3                    |1109                  |1
4          |100-105      | gr           | 518                | question4 | 518           |Text4                    |1110                  |1

修正数据,或修正联接。

您的加入是: Question.question_id = Question_Answer.question_id

但是,数据为: {1,2,3,4} <> {518}

连接错误或数据错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM