1

有谁知道这个查询发生了什么?我想要做的是如果表courseID不存在表中,则打印所有退出。但我不断收到错误操作数应包含 1 列elective_modulesgroup_elective_modulesgroup_elective_modules

这是我的查询

$alternativeEQuery = 
"SELECT elective_modules.courseID,elective_modules.yr 
 FROM elective_modules
 WHERE elective_modules.yr = '$year1' 
 AND elective_modules.courseID 
 NOT IN 
     (SELECT group_elective_modules.moduleID,group_elective_modules.courseName 
 FROM group_elective_modules 
 WHERE group_elective_modules.courseName = '$courseTitle'
 AND elective_modules.courseID = group_elective_modules.moduleID)";

$alternativeEResult = mysql_query($alternativeEQuery) or die($alternativeEQuery."<br/><br/>".mysql_error());
4

1 回答 1

4

此处的子查询中不能有两列:

(SELECT group_elective_modules.moduleID,group_elective_modules.courseName 
 FROM group_elective_modules 
 WHERE group_elective_modules.courseName = '$courseTitle'
 AND elective_modules.courseID = group_elective_modules.moduleID)

要么使用正确的,要么添加第二个not in子句并在那里使用另一个列名。

于 2012-08-08T09:39:20.960 回答