title: Select max date in a group where max date is less than current date
body: <p>I'm trying to execute a mysql query on this table data that would return the latest date that is less than the current date grouped by the booking number.</p>
  
  <p>Example of the table data: </p>
  
  <pre><code>bookingnumber | booking_date |
  ------------------------------
  11            | 2015-02-21   |
  11            | 2015-02-22   |
  11            | 2015-02-20   |
  12            | 2015-02-20   |   
  13            | 2015-02-22   |
  ------------------------------
  </code></pre>
  
  <p>If current date is 2015-02-21 I am striving to get this result:</p>
  
  <pre><code>bookingnumber | booking_date |
  ------------------------------
  12            | 2015-02-20   |
  </code></pre>
  
  <p>I have experimented with MAX, subquerys, and groups and this is the "best" I have managed to do so far:</p>
  
  <pre><code>"select bookingnumber, booking_date 
  FROM table 
  WHERE 
  (select max(booking_date) from table as f where f.bookingnumber = table.bookingnumber) 
  AND booking_date &lt; CURRENT_DATE"
  </code></pre>
  
  <p>This however gives me the result:</p>
  
  <pre><code>bookingnumber | booking_date |    
  ------------------------------
  12            | 2015-02-20   |   
  11            | 2015-02-20   |
  </code></pre>