Search code examples
mysqlerror-handlingprocedureworkbenchoperands

Error Code: 1241. Workbench, MySQL, cannot resolve the parameters


I am using Workbench for writing queries. The following procedure is successfuly created (no problems with it). But when trying to execute the function i get this error: Error Code: 1241. Operand should contain 1 column(s)
I will be thankfull if somebody help me with this.

delimiter $$
create procedure usp_raise_salaries1(department_name varchar(30))
begin

update employees as e
set salary = salary * 1.05
where (select first_name, salary from employees as e 
join departments as d on e.department_id = d.department_id
where d.name = department_name);


end $$

delimiter ;

set @answer = 'Sales';
call usp_raise_salaries(@answer); -- The Workbench gives error at this line.


Solution

  • You get many rows from your subquery so you need the 'IN clause to select the rows to update

    delimiter $$
    create procedure usp_raise_salaries1(department_name varchar(30))
    begin
    
    update employees as e
    set salary = salary * 1.05
    where (first_name, salary) IN (select first_name, salary from employees as e 
    join departments as d on e.department_id = d.department_id
    where d.name = department_name);
    
    
    end $$
    
    delimiter ;