MySQL: order by and limit gives wrong result

Could be this bug that was never resolved for your updated version? http://bugs.mysql.com/bug.php?id=31001

I am running 5.1.42 locally. I copy and pasted your queries from above and am getting all the correct results.. Whether it be the bug mentioned above or not, it sounds like a bug, and it appears to have been fixed in a more recent release than yours..


Seems peculiar, maybe a bug? As a workarount maybe you can make the selection explicit - use a subquery to select the MAX(id) and filter on that in a WHERE clause. E.g.

SELECT id, created_at FROM billing_invoices 
   WHERE id IN (SELECT MAX(id) FROM billing_invoices WHERE account_id=5)

Tags:

Mysql

Sql