title: MYSQL select where column value matches another value in same column
body: <p>I have a database table that contains values where the meta_id corresponds to the data in the meta_data column. But now i want to display that data inside a bootstrap table.</p>
  
  <p>I have a table like so in php myadmin</p>
  
  <p><img src="https://i.stack.imgur.com/WYGTC.png" alt="enter image description here"></p>
  
  <p>I would like the result to look like this:</p>
  
  <p><img src="https://i.stack.imgur.com/xFp94.png" alt="enter image description here"></p>
  
  <p>I currently have this query written up but im confused about how to best do this. </p>
  
  <p>I thought by counting the rows that exist and then dividing them by the table header count i should get table row loop that i can then insert my table columns into but its still creates more columns than i need.</p>
  
  <pre><code>&lt;?php     
  
  
  $sql="SELECT * FROM table WHERE pid=".$this-&gt;item-&gt;id." ORDER BY meta_data ASC";
  $db-&gt;setQuery($sql);
  $db-&gt;query();
  
  $count=$db-&gt;getNumRows();
  
  $meta= $db-&gt;loadObjectlist(); 
  
  foreach($meta as $data){ 
  $metadata .=  '&lt;td&gt;'.$data-&gt;meta_data.'&lt;/td&gt;'; 
  } 
  
  $count = $count/2; // i know there will be only two th's
  
  ?&gt;
  
  &lt;table class="table table-striped"&gt;
  
  &lt;thead&gt;&lt;tr&gt;&lt;th&gt;Item&lt;/th&gt;&lt;th&gt;Price&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;
  
  &lt;tbody&gt;
  
  &lt;?php for ($x = 1; $x &lt;= $count; $x++) { ?&gt;
  
  &lt;tr&gt;&lt;?php echo $metadata; ?&gt;&lt;/tr&gt;
  
  &lt;?php } ?&gt;
  
  &lt;/tbody&gt;
  
  &lt;/table&gt;
  </code></pre>
  
  <p>Which is doing this:</p>
  
  <p><img src="https://i.stack.imgur.com/VhYn3.png" alt="enter image description here">   </p>
  
  <p>Im getting close!</p>
  
  <pre><code>&lt;?php 
  
  $sql="
  
  SELECT * FROM table WHERE pid=".$this-&gt;item-&gt;id." 
  
  AND 
  
  meta_id IN (SELECT meta_id FROM table GROUP BY meta_id HAVING COUNT(*) &gt; 1)
  
  ";
  
  $db-&gt;setQuery($sql);
  $meta= $db-&gt;loadObjectlist(); 
  foreach($meta as $data){ 
  $metadata .=  '&lt;tr&gt;&lt;td&gt;'.$data-&gt;meta_data.'&lt;/td&gt;&lt;/tr&gt;'; 
  } 
  
  ?&gt;
  
  &lt;table class="table table-striped"&gt;
  
  &lt;thead&gt;&lt;tr&gt;&lt;th&gt;Item&lt;/th&gt;&lt;th&gt;Price&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;
  
  &lt;tbody&gt;
  
  &lt;?php echo $metadata; ?&gt;
  
  &lt;/tbody&gt;
  
  &lt;/table&gt;
  </code></pre>
  
  <p>The above is now giving me this:</p>
  
  <p><img src="https://i.stack.imgur.com/ULjXB.png" alt="enter image description here"></p>