Adding order by with offset and limit in mysql query

The ORDER BY clause should come before the LIMIT clause. This makes sense because you first want the record set to be ordered and then apply the limitation.

SELECT * FROM lead ORDER BY id DESC LIMIT 0, 5

You can use either LIMIT offset, row_ count syntax or the LIMIT row_count OFFSET offset.

Check: http://dev.mysql.com/doc/refman/5.0/en/select.html


You have to

select * from lead order by id desc LIMIT 5 OFFSET 0

The manual ( http://dev.mysql.com/doc/refman/5.0/en/select.html ) describes that LIMIT is only allowed to appear after the ORDER BY.

Tags:

Mysql