title: Intersection tables and queries and MySQL
body: <p>I'm building a StackOverflow mini-clone. I have the following database relations:</p>
  
  <pre><code>questions 
  - question_id
  - title
  
  tags
  - tag_id
  - name
  
  question_tags
  - foreign key tag_id
  - foreign key question_id
  </code></pre>
  
  <p>Supposedly, this is the proper way to organize a tagging system. </p>
  
  <p>Now, how could I query <strong>all</strong> questions with the tag 'java', and at the same time, when listing those questions, also <strong>show all the tags that each question is associated with</strong>?</p>
  
  <p>I feel like denormalizing and putting an extra field into <strong>questions</strong>, say <strong>tag_string</strong>, which would have a listing of <em>tags as CSV</em>, so I can have a simpler query for this case.</p>
  
  <p>Of course, it is not a problem when showing a single question:</p>
  
  <pre><code>  SELECT * FROM questions LEFT OUTER JOIN question_tags USING(question_id)
                            LEFT OUTER JOIN tags USING(tag_id)
                            WHERE question_id = 42;
  </code></pre>