title: Joining multiple tables in MySQL: "Unknown column"
body: <p>I'm running into an error with a simple <code>JOIN</code> in MySQL. Am I missing something obvious?</p>
  
  <pre><code>SELECT stop_times.stop_sequence
  FROM stop_times
  INNER JOIN stops ON stop_times.stop_id = stops.stop_id
  INNER JOIN trips ON stop_times.trip_id = trips.trip_id
  WHERE stops.stop_code = :stopCode;
  </code></pre>
  
  <p>Where <code>:stopCode</code> is a parameter that is bound via PDO.</p>
  
  <p>The error I'm getting is: <code>SQLSTATE[42S22]: Column not found: 1054 Unknown column 'stop_times.trip_id' in 'on clause''</code></p>
  
  <p>The database schema for these three tables are:</p>
  
  <pre><code>stop_times
  ----------
  trip_id VARCHAR(23) NOT NULL -- PK
  arrival_time TIME NOT NULL
  departure_time TIME NOT NULL
  stop_id INT(10) UNSIGNED NOT NULL -- PK
  stop_sequence INT(10) UNSIGNED NOT NULL -- PK
  
  
  stops
  -----
  stop_id INT(10) UNSIGNED NOT NULL -- PK
  stop_code INT(5) UNSIGNED NULL
  stop_name VARCHAR(53) NOT NULL
  stop_lat DECIMAL(8, 6) NOT NULL
  stop_lon DECIMAL(9, 6) NOT NULL
  stop_url VARCHAR(66) NULL
  
  trips
  -----
  route_id INT(8) UNSIGNED NOT NULL
  service_id VARCHAR(6) NOT NULL
  trip_id VARCHAR(23) NOT NULL -- PK
  trip_headsign VARCHAR(255) NOT NULL
  </code></pre>
  
  <p>I've also tried using aliases but that didn't work. Running the query in Microsoft Access works, the SQL that is produced has brackets around the JOIN statements though.</p>
  
  <p>Why is my query not working?</p>