title: SQL Query Optimization help
body: <p>my foundation on SQL is pretty weak so I hope you could bear with me. I have three tables: contents, categories, and categorization. The setup was chosen since some content will belong to one or more categories.</p>
  
  <p>I want to fetch contents and its corresponding categories.</p>
  
  <p>This is an overly-simplified version of the current script, without error-checking routines:</p>
  
  <pre><code>$q = "SELECT * FROM contents WHERE contents.foo = 'bar'"
  $resource = mysql_query($q);
  $categoryFilter = array();
  
  $q2 = "SELECT * FROM categorization WHERE ";
  while($content = mysql_fetch_assoc($resource))
  {
      $categoryFilter[] = "content_id='" . $content["id"] . "'";
  }
  
  if(count($categoryFilter))
  {
      $q2 .= implode(" OR ", $categoryFilter);
      mysql_query($q2);
  }
  </code></pre>
  
  <p>That's the gist of it. I hope you get what I am trying to do. I don't know if I can actually use JOINS the <code>content_id</code> may be present in multiple rows in <code>categorization</code>. So what I did was to simply append multiple <code>OR</code>'s, trying to fetch items one by one. I really would not like to use multiple queries in this scenario.  I hope anyone could suggest an approach</p>
  
  <p>Thanks for your time</p>