How to store query result in a variable in MySql stored Procedure
<p>I want to store the result (1 column) of a query in variable so that i can reuse it again in another queries for filtering</p>

<p>Ex:</p>

<p>student table</p>

<pre><code>+----+------+------------+--------------+-------+
| id | name | dob        | email        | group |
+----+------+------------+--------------+-------+
| 1  | Sam  | 1990-12-12 | sam@test.com | 1     |
+----+------+------------+--------------+-------+
| 2  | Tom  | 1990-12-11 | tom@test.com | 1     |
+----+------+------------+--------------+-------+
| 3  | Kim  | 1990-11-11 | kim@test.com | 2     |
+----+------+------------+--------------+-------+
</code></pre>

<p><strong>Query</strong></p>

<pre><code>select id from student  where  group=1;
</code></pre>

<p>this will give me </p>

<pre><code>+----+
| id |
+----+
| 1  |
+----+
| 2  |
+----+  
</code></pre>

<p>What I want to achieve is to store the above result in a variable so that i can reuse it in a Procedure like this in multiple queries.</p>

<pre><code>select * from address where std_ref_id in (@theVariable);

select * from some_table where std_ref_id in (@theVariable);
</code></pre>