I am trying to create a MySQL function using phpMyAdmin and getting this error.
#1415 - Not allowed to return a result set from a function
that is because you are using SELECT
queries whose output is not stored into variables or temporary inside FUNCTION
which must. Function can return only one single value. So your code should be something like this:
CREATE TABLE t1 AS SELECT left_id AS c1 FROM mlm_user_mst WHERE parent_id=a AND left_id>0;
CREATE TABLE t2 AS SELECT right_id AS c2 FROM mlm_user_mst WHERE parent_id=a AND right_id>0;
or
SELECT left_id AS c1 INTO @c1 FROM mlm_user_mst WHERE parent_id=a AND left_id>0 LIMIT 1;
SELECT right_id AS c2 INTO @c2 FROM mlm_user_mst WHERE parent_id=a AND right_id>0 LIMIT 1;
Because
SELECT left_id AS c1 FROM mlm_user_mst WHERE parent_id=a AND left_id>0;
doesn't set the variable c1, it returns a set with a column named c1
You want
SELECT left_id INTO c1 FROM mlm_user_mst WHERE parent_id=a AND left_id>0;
Similarly for c2.