2

I'm running this query in MYSQL and I'm getting the error 1241: Operand should contain 1 column(s).

I want to know the names and student id's of the students enrolled in Database Management Systems and Knowledge Discovery in Databases (both course titles in the CoursesOffer table)

  • Students(stuID: String, stuName: String, gender: String, birthdate: Date, enterYear: Year, gpa: Float)
  • Departments(deptName: String, numPhDs: Integer)
  • ProfessorWorks(profID: String, profName: String, deptName: String)
  • CoursesOffer(cNo: String, cTitle: String, deptName: String)
  • Majors(deptName: String, stuID: String, degreeProgram: String, attendYear: Year, attendSemester: String)
  • Sections(cNo: String, semester: String, sectNo: String, profID: String)
  • Enrolls(stuID: String, cNo: String, sectNo: String, semester: String, grade: String)

My query looks like

SELECT S.StuName, S.StuID 
FROM Students S NATURAL JOIN CoursesOffer C NATURAL JOIN Enrolls E 
WHERE cTitle='Database Management Systems'
IN (
SELECT S2.StuName, S2.StuID 
FROM Students S2 NATURAL JOIN CoursesOffer C2 NATURAL JOIN Enrolls E2 
WHERE cTitle='Knowledge Discovery in Databases');
1
  • IN is (logical) operator for the WHERE clause, it is used in the form val1 IN (<list fo values or a subquery>) and can be "extended" to use tuples like (val1, val2) IN (<list of pairs>) - so reading your code what you wrote seems to mean: "compare cTitle to 'Database Management Systems' and then check the result (0 or 1 for false/true) using the IN operator" - but it expects to get ONE column only to compare to the 0/1
    – jkavalik
    Commented Oct 14, 2015 at 6:07

1 Answer 1

1

You probably want to replace:

WHERE cTitle='Database Management Systems'
IN (
SELECT S2.StuName, S2.StuID 
...
  ) ;

with:

WHERE cTitle='Database Management Systems'
  AND (S.StuName, S.StuID) IN (                -- this changed
SELECT S2.StuName, S2.StuID 
...
  ) ;
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.