Question

does anyone knows what's going on with this query please ?. What I am trying to do is if courseID in elective_modules table doesn't exist in group_elective_modules table, then print all exit in group_elective_modules. But I keep getting the error Operand should contain 1 column(s)

Here is my query

$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());
Was it helpful?

Solution

You can't have two columns in the subquery here:

(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)

Either use the right one, or add in a second not in clause and use the other column name there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top