title: Group by id having max(date_field)
body: <p>To build a report, I must select some information on the last transaction status of all my customers. Until now, this is what I got:</p>
  
  <pre><code>SELECT c.firstname, c.lastname, d.product_name, o.payment, s.name, h.date_add
  FROM ps_orders o
  INNER JOIN ps_order_detail d ON d.id_order = o.id_order
  INNER JOIN ps_customer c ON c.id_customer = o.id_customer
  INNER JOIN ps_order_history h ON o.id_order = h.id_order
  INNER JOIN ps_order_state_lang s ON s.id_order_state = h.id_order_state
  WHERE s.id_lang =6
  GROUP BY c.id_customer
  HAVING MAX(h.date_add)
  </code></pre>
  
  <p>For each customer, this query is selecting the first date (the field <strong>h.date_add</strong>) when I need of the last one. It seems the MySQL is ignoring the <strong>HAVING</strong>. </p>
  
  <p>I tried to make a sub-select, but it doesn't work too.</p>
  
  <p>Thanks any answer. </p>