我有一个关于 mysql 的问题。
我有几个表,例如course
、papers
、students
、studentspapers
现在我想要的是我的查询应该返回如下结果:
它应该从学生表中选择学生姓名、学生类别,从学生论文中选择学生可选论文,但我没有在我的学生论文表中提及任何内容,而是在论文表中提及。
Papers 表有 id 作为主键,我在 studentspaper 中使用它作为外键。
现在我使用的简单查询是:
select
st.name,
s.paperid
from
students st,
sps s join papers
on paperid
where
paperid = (select p.p_id from papers p where type='optional')
and st.course=1
我不知道该怎么办。
它说子查询返回超过 1 行 #1242
最佳答案
在这种情况下,您必须将 SQL 更改为:
select st.name, s.paperid
from students st, sps s join papers on paperid
where paperid in (select p.p_id from papers p where type='optional') and st.course=1
我刚刚将“=”更改为“in”。
这应该可以解决您的问题。
关于mysql - #1242 : Subquery Returns more than one row,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11547265/