title: How do I query the following pivot table in MySQL?
body: <p>I'm pretty new to SQL and I've been learning a bit about pivot tables. Now, I'm trying to query 3 tables simultaneously but cannot get it working. </p>
  
  <p>Here are the tables I currently have:</p>
  
  <p><strong>products table</strong></p>
  
  <pre><code>|    p_id   |    name    |
  |------------------------|
  |     1     |    ItemA   |
  |------------------------|
  |     2     |    ItemB   |
  </code></pre>
  
  <p><strong>category table</strong></p>
  
  <pre><code>|  cat_id   |    cat     |
  |------------------------|
  |     1     |    catA    |
  |------------------------|
  |     2     |    catB    |
  </code></pre>
  
  <p>** prod_cat pivot table with prod and cat as FK**</p>
  
  <pre><code>|    prod   |    cat     |
  |------------------------|
  |     1     |    1       |
  |------------------------|
  |     2     |    1       |
  |------------------------|
  |     1     |    2       |
  |------------------------|
  |     2     |    2       |
  </code></pre>
  
  <p>The pivot table basically allows me to have multiple categories for each product. I'm pretty sure that my logic is good with the table setup(I might be wrong) but the problem I'm having is I'm not really sure how to query all 3 of them to <code>output all the categories that the item belongs to</code>. I'm not sure how to show this in a table, so if you require more detail to the question, drop a comment and I'll do my best to edit it.</p>
  
  <p>Any help would be appreciated. </p>