MySQL limit from descending order

前端 未结 4 1394
死守一世寂寞
死守一世寂寞 2020-12-30 23:56

Is it available to write a query to use same \"LIMIT (from), (count)\", but get result in backwards?

In example if I have 8 rows in the table and I want to get 5 row

4条回答
  •  梦毁少年i
    2020-12-31 00:25

    Let's say we have a table with a column time and you want the last 5 entries, but you want them returned to you in asc order, not desc, this is how you do it:

    select * from ( select * from `table` order by `time` desc limit 5 ) t order by `time` asc
    

提交回复
热议问题