Iterate till parent in mysql works but not if given value is array
<p>I have a table as below:</p>

<pre><code>Id     Name    Parent_id
1      One     0
2      Two     0
3      Three   2
4      Four    1
5      Five    0
6      Six     4
7      Seven   1
8      Eight   3
9      Nine    5
10     Ten     8
</code></pre>

<p>SQL Query which works fine if i provide <strong>single id</strong> as a value</p>

<pre><code>SELECT T2.id, T2.name
FROM (

    SELECT @r AS _id, (SELECT @r := parent_id FROM category WHERE id = _id) AS parent_id

    FROM (SELECT @r := 10 ) vars, category h

    WHERE @r &lt;&gt; 0) T1

JOIN category T2
ON T1._id = T2.id
</code></pre>

<p>Here is the <a href="http://sqlfiddle.com/#!9/1def5/4" rel="nofollow">SQL Fiddle</a> for the above working query.</p>

<blockquote>
  <p>I have to assign Array here <code>FROM (SELECT @r := 10 )</code> instead of value <strong>10</strong>
  But i don't know how to apply that</p>
  
  <blockquote>
    <p>I also need to iterate all the values of the array</p>
  </blockquote>
</blockquote>

<p>I have a situation where i need to pass <strong>Array of id</strong> as a value and get the parent tree of all the respective id's in the array. I tried many things search for it over the net, still am not able to tackle it out as i am not much known to sql queries.</p>

<blockquote>
  <p>Also if any optimized method is there to achieve the same, will be highly appreciated.</p>
</blockquote>

<p>Thanks :)</p>