title: INNER JOIN on three tables with condition
body: <p>I am trying to fetch all the photos detail from a tag slug <em>(URL for the tag)</em>, the database has three tables:</p>
  
  <pre><code>|-----------------------|
  |==&gt; photo              |
  |   -&gt; id               |
  |   -&gt; custom_id        |
  |   -&gt; title            |
  |-----------------------|
  |==&gt; tags               |
  |   -&gt; id               |
  |   -&gt; slug             |
  |-----------------------|
  |==&gt; tags_relation      |
  |   -&gt; tid              | &lt;-- this is the tags.id
  |   -&gt; pid              | &lt;-- this is the photo.custom_id
  |-----------------------|
  </code></pre>
  
  <p>here is my mysql code to INNER JOIN all the tables and to get 20 photos from a tag:</p>
  
  <pre><code>SELECT photo.*, tags.*, tags_relation.*, 
  FROM tags WHERE tags.slug = 'people' 
  INNER JOIN tags_relation ON = tags_relation.tid = tags.id 
  INNER JOIN photo ON photo.custom_id = tags_relation.pid
  LIMIT 20  
  ORDER BY photo.date DESC
  </code></pre>
  
  <p>The query is not correct anyway, and i can't understand how the INNER JOIN should work here, any idea?
  Thanks</p>