title: MySQL Stored Procedure - how to reference internally created recordset
body: <p>I am curious how to reference an existing stored procedure SELECT statement from a secondary query or SET call within the same stored procedure.</p>
  
  <p>For example:</p>
  
  <pre><code>CREATE PROCEDURE 'mysp' (OUT sumvalue INT)
  BEGIN
      -- This is the core recordset the SP returns
      SELECT * FROM Table
  
      -- I also want to return a value based on the above recordset
      SET sumvale = SUM(previousselect.values)
  END
  </code></pre>
  
  <p>Essentially, I have a SP that returns a detailed recordset, and I need to return SUM and custom values based on the data within that recordset. The issue is I cannot figure out how to reference the data after the SELECT statement (e.g. does it create an internal reference I can use such as @recordset1.X).</p>
  
  <p>Any help would be appreciated.</p>