I have a table with a persons id as the primary key which contains their manager's id. I want to set up a while loop that will display all of that person's managers ids, all the way to the top of the list. I built a while loop, but it's returning null. What am I doing wrong?
CREATE FUNCTION `whilefunction`() RETURNS varchar(255)
BEGIN
declare l_loop varchar(25) default '123456';
declare result varchar(255) default '';
while l_loop is not null do
set result = result + (select managerid from table where personid = l_loop);
set l_loop = (select managerid from table where personid = l_loop);
end while;
RETURN result;
END