title: Order by the nearest date in the joined table with a where condition - MySQL
body: <p>-Hello!</p>
  
  <h2>I have those 2 tables:</h2>
  
  <pre><code>     1.events                             2.eventdates 
  +------------------+         +---------------------------------------+
  | id |    title    |         | id | event_id |    date    | bookable |
  +------------------+         +---------------------------------------+
  | 1  |   event1    |         | 1  |     1    | 2010-03-25 |     1    |
  | 2  |   event2    |         | 2  |     1    | 2012-02-20 |     1    |
  | 3  |   event3    |         | 3  |     2    | 2014-12-15 |     1    |
  +------------------+         | 4  |     2    | 2014-10-28 |     1    | &lt;
                               | 5  |     2    | 2014-10-24 |     0    |
                               | 6  |     3    | 2014-11-30 |     1    | &lt;
                               | 7  |     3    | 2014-06-17 |     1    |
                               | 8  |     1    | 2014-12-25 |     0    |
                               +---------------------------------------+
  </code></pre>
  
  <h2>Objective:</h2>
  
  <p>The objective is to display each event by next available (ORDER BY) with: </p>
  
  <ul>
  <li>his next date if exists and if bookable</li>
  <li>empty if no corresponding result</li>
  </ul>
  
  <p>If today is  2014-10-17 it should be something like:</p>
  
  <pre><code>'event2', '2014-10-28'
  'event3', '2014-11-30'
  'event1', '' (or NULL)
  </code></pre>
  
  <p>--</p>
  
  <p>I really need that in the same query because I want to use a pagination on the events.
  This is the reason I can't sort data after my query with php ...</p>
  
  <p>I wasn't able to do it with a simple left join because of the WHERE <code>bookable</code> that exclude event 1 from the query.</p>
  
  <p>I have also tried with subqueries but I can't manage to get the next date of each event.</p>
  
  <p>--</p>
  
  <p>Does someone have and idea or a query I can test to get the desired result?</p>
  
  <p>All help is appreciated.</p>
  
  <p>Thank you!</p>