How to fix "ERROR 1241 (21000): Operand should contain 1 column(s)" in mysql?

338 Views Asked by At

i want to display details of drivers working in morning shift..

delimiter //
create function dShift(n int)
returns varchar(128)
deterministic
begin
return (select driver.driver_no,driver_name,licence_no,address,d_age,salary 
from driver,bus_driver as bd where bd.shift=n and bd.driver_no = 
driver.driver_no); 
end //
1

There are 1 best solutions below

2
Arulkumar On

In your function the return type is varchar returns varchar(128). So it expects a single string as output. But you are returning 6 columns as output.

You can use the following way to get the list of columns as output:

delimiter //

CREATE FUNCTION dShift (n INT)
BEGIN
    SELECT driver.driver_no
        ,driver_name
        ,licence_no
        ,address
        ,d_age
        ,salary
    FROM driver
    JOIN bus_driver AS bd ON bd.driver_no = driver.driver_no
    WHERE bd.shift = n;
END //