joseph koh
joseph koh

Reputation: 33

How can I fix Error code 1241 in MySQL

SELECT c.Staff_no, c.Start_datetime, c.End_datetime, s.First_name, s.Profession, s.Department, s.Gender
 FROM duty_roster_1501003f c, staff_1501003f s where c.Staff_no = s.Staff_no IN
 (SELECT Staff_no, Start_datetime, End_datetime FROM duty_roster_1501003f WHERE Remarks = 'overtime' ORDER BY staff_no);

The error code says Operand should contain 1 column(s). What should i do to fix it?

Upvotes: 1

Views: 103

Answers (2)

J. V. A.
J. V. A.

Reputation: 529

Where you say:

...  WHERE c.Staff_no = s.Staff_no IN (SELECT Staff_no, Start_datetime, End_datetime FROM duty_roster_1501003f WHERE Remarks = 'overtime' ORDER BY staff_no);

That is not valid. Maybe you want:

...  WHERE c.Staff_no = s.Staff_no AND c.Staff_no IN
      (SELECT Staff_no FROM duty_roster_1501003f WHERE Remarks = 'overtime')

A select for an IN can only return 1 column (what would you have it do with the other columns?)

Upvotes: 1

Nico Andrade
Nico Andrade

Reputation: 910

You're missing an AND/OR and a field name before IN

WHERE c.Staff_no = s.Staff_no AND someField IN (Subquery)

Also, the subquery should return only one field, and not 3 as you're returning now.

Upvotes: 1

Related Questions