select questions.quesid, questions.question, questionsoptions.optionid
from questions
inner join questionsoptions on questions.quesid = questionsoptions.quesid;
如何从列quesid中删除重复数据,问题和列选项ID保持不变
答案 0 :(得分:2)
在你的结果中,所有具有相同quesid的行,问题都有不同的optionid。这使得所有这些行都不同。所以如果你想为一个quesid设置一行,你需要聚集结果。
例如
select questions.quesid, questions.question, count(questionsoptions.optionid)
from questions inner join questionsoptions on questions.quesid = questionsoptions.quesid
group by questions.quesid, questions.question;
答案 1 :(得分:1)
如果您希望在同一行中包含所有optionid
值,可以使用GROUP_CONCAT
来完成,这将创建一个字符串,其中所有ID都以逗号分隔。
SELECT questions.quesid, questions.question, GROUP_CONCAT(questionsoptions.optionid)
FROM questions INNER JOIN questionsoptions ON questions.quesid = questionsoptions.quesid
GROUP BY questions.quesid, questions.question;