Select last 20 order by ascending – PHP/MySQL

First, select last 20 entries. Then sort them in ascending order. You can easily do this in a single query (with subquery):

select * from (
    select * from your_table order by id desc limit 20
) tmp order by tmp.id asc

Leave a Comment