title: How to call stored procedure multiple time in binary tree
body: <p>It's a binary tree table. I have two fields as leg1 and leg2.if leg1 is != empty and leg2 is empty, i can call the procedure recursively. and viceversa. but when leg1 and leg2 !=  empty how to call the procedure recursively.(CALL <code>getFinal11</code>(<code>next_leg2_name</code>, <code>result</code>); CALL <code>getFinal11</code>(<code>next_leg1_name</code>, <code>result</code>);</p>
  
  <pre><code>DELIMITER $$
  CREATE PROCEDURE `getFinal11`(IN `param_name` VARCHAR(255), OUT `result` VARCHAR(65535))
  BEGIN
    DECLARE `next_leg1_name` VARCHAR(255);
    DECLARE `next_leg2_name` VARCHAR(255);
  
    SELECT `leg1` INTO `next_leg1_name` 
    FROM `matrix` 
    WHERE `username` = `param_name`;
  
    SELECT `leg2` INTO `next_leg2_name`
    FROM `matrix`
    WHERE `username` = `param_name`;
  
    IF `next_leg1_name` &lt;&gt; '' AND  `next_leg2_name` = '' THEN
      CALL `getFinal11`(`next_leg1_name`, `result`);
      SET `result` := CONCAT(`next_leg1_name`, ',', IFNULL(`result`, ''));
    END IF; 
  
    IF `next_leg2_name` &lt;&gt; '' AND `next_leg1_name` = '' THEN
      CALL `getFinal11`(`next_leg2_name`, `result`);
      SET `result` := CONCAT(`next_leg2_name`, ',', IFNULL(`result`, ''));
    END IF;  
  
    IF `next_leg2_name` &lt;&gt; '' AND `next_leg1_name` &lt;&gt; '' THEN
      CALL `getFinal11`(`next_leg2_name`, `result`);
      CALL `getFinal11`(`next_leg1_name`, `result`);
      SET `result` := CONCAT(`next_leg2_name`, ',', IFNULL(`result`, ''));
      SET `result` := CONCAT(`next_leg1_name`, ',', IFNULL(`result`, ''));
    END IF;  
  
    IF `next_leg2_name` = '' AND `next_leg1_name` = '' THEN
      SET `result` := '';
    END IF;
  END$$
  DELIMITER ;
  </code></pre>