Hello I am trying to create a mysql stored function that used "UNION ALL" but the result is this:

1415 - Not allowed to return to result set from a function

How can I solve it?

> > > DELIMITER $$ > > CREATE DEFINER = root@localhost FUNCTION F_GET_CLIENT_CREDIT( > > IGUESTCLIENTNUM INT(11), > > IGROUPCD INT(11), > > ILOCALCD INT(11) > > ) RETURNS DOUBLE > BEGIN > > SELECT SUM(TOTAL) FROM ( > > SELECT > SUM(CASHPRECIO+CHECKPRECIO+COUPONPRICE-TOTALPRECIO) AS TOTAL > FROM TVENTA > WHERE STATCD = '3200' AND GUESTNUM = IGUESTCLIENTNUM AND GROUPCD = IGROUPCD AND LOCALCD = ILOCALCD > GROUP BY GROUPCD, LOCALCD, GUESTNUM > > UNION ALL > > SELECT SUM(CASHPRECIO+CHECKPRECIO+COUPONPRICE-TOTALPRECIO) AS TOTAL > FROM TVENTAOLD > WHERE STATCD = '3200' AND GUESTNUM = IGUESTCLIENTNUM AND GROUPCD = IGROUPCD AND LOCALCD = ILOCALCD > GROUP BY GROUPCD, LOCALCD, GUESTNUM > > UNION ALL > > SELECT SUM(PRICE) AS TOTAL > FROM TMNGBANK > WHERE STATCD = '1000' AND CHECKFLAG = 'Y' AND CLIENTNUM = IGUESTCLIENTNUM AND GROUPCD = IGROUPCD AND LOCALCD = ILOCALCD > GROUP BY GROUPCD, LOCALCD, CLIENTNUM > > UNION ALL > > SELECT SUM(TOTALPRECIO) AS TOTAL > FROM TMNGCREDIT > WHERE STATCD = '1000' AND CLIENTNUM = IGUESTCLIENTNUM AND GROUPCD = IGROUPCD AND LOCALCD = ILOCALCD > GROUP BY GROUPCD, LOCALCD, CLIENTNUM > > UNION ALL > > SELECT SUM(NOTEPRICE) AS TOTAL > FROM TMNGNOTE > WHERE STATCD = '1000' AND CLIENTNUM = IGUESTCLIENTNUM AND GROUPCD = IGROUPCD AND LOCALCD = ILOCALCD > GROUP BY GROUPCD, LOCALCD, CLIENTNUM > ) AS TOTALCREDIT > LIMIT 1 ; > RETURN TOTAL_CREDIT; > END $$ > DELIMITER ;