Hi,
I have the following query:
$select = "SELECT c.username, o.order_id, MAX(o.order_timestamp)";
$from = " FROM customers c, orders o";
$where = " WHERE c.username = o.username";
$group = " GROUP BY o.order_id";
$query = $select.$from.$where.$group;
The result of this query does not satisfy me, because I do not get the order_id corresponding to the max order_timestamp.
Is there a way to make them match, EXCEPT FOR using MAX(o.order_id)?
FYI, the reason why I am asking this is because as soon as I try to sort the results (ORDER BY), I cannot use "ORDER BY MAX(o.order_timestamp)" (this gives an error).
Thanks!