title: php mysql join query on same table using pdo
body: <p>This is my table in which ID is table's primary key and SUPER_ID is used to manage hierarchy for example here, A is super user of B and B is super user of C while A is super-super user of C............
  <strong>ID AND SUPER_ID MAY NOT NECESSARY BE SEQUENTIAL</strong>
  <a href="https://i.stack.imgur.com/KBpdQ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KBpdQ.jpg" alt=""></a></p>
  
  <p>Now question is when A is logged in, He can see details of his own and of Both B and C While B is logged in He can see details of His own and C only. And C can see his own details only.</p>
  
  <p>I have written this query:</p>
  
  <pre><code>&lt;?php
  $sql="SELECT * from TABLE 
  WHERE 
  ID =:loginId OR                                                  
  ID IN 
  (
  SELECT ID FROM TABLE 
  WHERE SUPER_ID =:SuperId
  )";
  $stmt = $conn-&gt;prepare($sql);
  $stmt-&gt;execute(array(':logedIn' =&gt; $_SESSION['sess_login_id'] , ':SuperId' =&gt; $_SESSION['sess_login_id']) );
  ?&gt;
  </code></pre>
  
  <p>This query gives me results of A and B when i logged in as User A.
  What query should I write so that I can get results of A , B and C when I logged in as User A?
  Because A is a super user of B and super-super user of C. Please help. Thank You.</p>