title: How to SELECT multiple key/value pairs where the key is constant?
body: <p>I have two tables, which I'll call <code>foo</code> and <code>bar</code>. Each table has a primary key, <code>foo_id</code> and <code>bar_id</code>, respectively. Each row in <code>foo</code> can be part of a group, which is a row in <code>bar</code> - think members on a committee, each member can be on multiple committees and each committee can have multiple members. I have a joining table which can be called <code>foo_bar</code>, which has only two columns (one each for the primary key of the other two tables) and lists which foo is part of which bar:</p>
  
  <pre><code>| foo_id | bar_id |
  | ------ | ------ |
  |   test |    res |
  |   test |   res2 |
  | --------------- |
  </code></pre>
  
  <p>Here is my PHP (due to my webhost I am unable to use <code>$stmt-&gt;get_result()</code>):</p>
  
  <pre><code>$stmt = $db-&gt;prepare("SELECT bar_id FROM foo_bar WHERE foo_id = ?");
  
  $stmt-&gt;bind_param("s", "test");
  $stmt-&gt;execute();
  $stmt-&gt;bind_result($result);
  $stmt-&gt;fetch();
  $stmt-&gt;close();
  </code></pre>
  
  <p>Right now, printing <code>$result</code> gives me "res". How do I make it so that my result is all of the bars that the <code>test</code> foo is part of?</p>
  
  <p><strong>SQL Fiddle:</strong> <a href="http://sqlfiddle.com/#!9/2dfd2/1" rel="nofollow noreferrer">http://sqlfiddle.com/#!9/2dfd2/1</a></p>