请教一个简单的语句
select * from course where courseid =(select courseid from stuselect where stuid = ' "+strLoginuser+ " ')
上面是我的语句,但提示我 "子查询返回的值多于一个 ",本意就是从course 中选择,
courseid 等于stuselect中的 courseid 的内容, stuselect中我没有设主健 ,如何解决呀
------解决方案--------------------select * from course where exists
(select courseid from stuselect where stuid = ' "+strLoginuser+ " ')
------解决方案--------------------把=改为 in或者在子查询中使用top
try:
select * from course where courseid in(select courseid from stuselect where stuid = ' "+strLoginuser+ " ')
select * from course where courseid =(select top 1 courseid from stuselect where stuid = ' "+strLoginuser+ " ')
------解决方案--------------------如果想用exists,可以这样:
select * from course where exists
(select 1 from stuselect where course.courseid =stuselect.courseid AND stuselect.stuid = 'E10314060 ')
------解决方案--------------------exists 判断是否返回行。要是在子查询中能返回行就执行外边(左边)的SELECT 语句。
具体看SQL 帮助