title: How can i get records of id those are connected in multiple row value
body: <p>Following is my table </p>
  
  <pre><code>Id      User_id     type               content       item_id    secondary_item_id
     879       1         activity_comment   Amazing       833        833
     907       168       activity_comment   Great         833        879    
     908       1         activity_comment   Welcome       833        907 
  </code></pre>
  
  <p>I want to output a comment reply structure, which can be described by an example. On the table above you can see user_id <code>1</code> post comment on <strong>833</strong> <code>( this is a post id )</code> a post, then <code>user 168</code> repliy to him as "Great" then after again <code>user 1</code> replay to user 168.</p>
  
  <p>So it could be like...</p>
  
  <pre><code>**MY POST** ( This is a post )
  
  ---- First comment( Amazing)
  ------- replay comment  (Great)
  ------------ sub replay (Welcome )
  </code></pre>
  
  <p>I have written the following query but I could not get the output that I expect.</p>
  
  <p>SQL Query:</p>
  
  <pre><code>&lt;?php 
    $listReplay =$wpdb-&gt;get_results("(SELECT * FROM table_one WHERE id = ".$value['secondary_item_id']."  AND type ='activity_comment') UNION DISTINCT 
                              (SELECT * FROM table_one WHERE secondary_item_id = ".$value['secondary_item_id']." AND type ='activity_comment')");
  ?&gt;
  </code></pre>