title: Can somebody explain what is wrong with this INNER JOIN?
body: <p>Simplified, I have three tables in a MySQL database:</p>
  
  <pre><code>sessions
  - id
  - title
  - training_programme_id
  
  session_attendees
  - id
  - sessions_id
  - users_id
  
  users
  - id
  - name
  </code></pre>
  
  <p>I am trying to count the number of sessions that a user is attending on a given training programme. When a user is set to attend a session, their ID is added to <code>session_attendees.users_id</code> and the session ID is added to <code>session_attendees.sessions_id</code>. Here is my SQL to count (as <code>result</code>) the number of sessions attended by a user with ID <code>10</code> when the training programme ID is <code>1</code>:</p>
  
  <pre><code>SELECT count(*) AS result FROM session_attendees 
     INNER JOIN sessions 
     ON (session_attendees.sessions_id = sessions.id) 
     WHERE (session_attendees.users_id = 10 AND sessions.training_programme_id = 1);
  </code></pre>
  
  <p>Now I know from directly inspecting the database that <code>session_attendees</code> contains 7 sessions where <code>users_id = 10</code> and all of those sessions have a <code>training_programme_id = 1</code>.</p>
  
  <p>Am I misunderstanding an INNER JOIN?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Here's a couple of images to illustrate my tables:</p>
  
  <p><img src="https://i.stack.imgur.com/ZCYpj.png" alt="enter image description here"></p>
  
  <p>As you can see I've sorted by user ID so you can see the 7 entries for ID = 10.</p>
  
  <p><img src="https://i.stack.imgur.com/ctalz.png" alt="enter image description here"></p>