title: Select max Id from output of executing a prepare statement result
body: <p>I have the following prepare statement in which I have kept the limit clause variable - </p>
  
  <pre><code>PREPARE fooStmt FROM "SELECT id FROM Table_1 ORDER BY id LIMIT ?";
  </code></pre>
  
  <p>I define a variable @record - </p>
  
  <pre><code>SET @record = 4;
  </code></pre>
  
  <p>Now I use the above variable to execute the prepared statement - </p>
  
  <pre><code>EXECUTE fooStmt USING @record;
  </code></pre>
  
  <p>I get the below result - </p>
  
  <pre><code>+----+
  | id |
  +----+
  |  1 |
  |  2 |
  |  3 |
  |  4 |
  +----+
  </code></pre>
  
  <p>Now my problem is that I want the max id from the above result. 
  I tried the below query for obtaining the desired result, but it gives me SQL syntax error : </p>
  
  <pre><code>select max(id) from (EXECUTE fooStmt USING @record);
  ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'USING @record)' at line 1
  </code></pre>
  
  <p>Can you please help me to identify the problem and how can I get my desired result?</p>