Mysql error Operand should contain 1 column(s)
1. An error
ERROR 1241 (21000): Operand should contain 1 column(s)
2. Report the cause of the error
This statement mostly occurs because the result set of the SELECT is wrapped in (). It is normal to enclose ()
with select
, but it is possible that the fields are misused, as shown in the following SQL:
select
pit_key
,employee_code
,department_id
,value_date
from pit_employee_department ped
where ped.employee_code = 'GSCQ3349'
and ped.value_date < date_format(date_sub(curdate(), interval day(curdate()) - 1 day),'%Y%m%d')
and ped.pit_key not in
( select
pit_key
,value_date
from pit_employee_department ped_1
inner join
(
select
max(value_date) as max_date
from pit_employee_department ped
where ped.value_date <= date_format(date_sub( date_sub(curdate(), interval day(curdate()) - 1 day),interval 1 month),'%Y%m%d')
and employee_code = 'GSSH0039'
)ped_2
on ped_1.value_date < ped_2.max_date
and ped_1.employee_code = 'GSSH0039'
);
The reason for executing this error in the above SQL statement is that pit_key
and value_date
are used in the subquery, and the comparison option is pit_key not in (...).
, field inconsistency results in an error.
3. Solutions
Make changes for different reasons.