title: How can I achieve this double join in SQL?
body: <p>I have this query, which joins the names of events which are stored in a cache table.</p>
  
  <pre><code>SELECT OccurrenceCache.occurrence_date, CalendarItem.summary FROM OccurrenceCache
      INNER JOIN CalendarItem ON CalendarItem.ROWID = OccurrenceCache.event_id
      WHERE OccurrenceCache.occurrence_date &gt;= (strftime('%s', 'now', 'localtime', 'start of day') - strftime('%s', '2001-01-01', 'start of day')) AND OccurrenceCache.occurrence_end_date &lt;= (strftime('%s', 'now', 'localtime', 'start of day') - strftime('%s', '2001-01-01', 'start of day') + 24 * 60 * 60);
  </code></pre>
  
  <p>Now I want to include location data of the events too, which are stored in a table named <em>Location</em>. The location entries are referenced by CalendarItem.location_id (0 means that no location is specified). I tried it with another JOIN-statement, but it does not work:</p>
  
  <pre><code>SELECT OccurrenceCache.occurrence_date, CalendarItem.summary, Location.title FROM OccurrenceCache
      INNER JOIN CalendarItem ON CalendarItem.ROWID = OccurrenceCache.event_id
      INNER JOIN Location ON Location.ROWID = CalendarItem.location_id
      WHERE OccurrenceCache.occurrence_date &gt;= (strftime('%s', 'now', 'localtime', 'start of day') - strftime('%s', '2001-01-01', 'start of day')) AND OccurrenceCache.occurrence_end_date &lt;= (strftime('%s', 'now', 'localtime', 'start of day') - strftime('%s', '2001-01-01', 'start of day') + 24 * 60 * 60);
  </code></pre>
  
  <p>It returns 0 results.</p>