N
N
ninja op op2020-05-08 11:52:42
MySQL
ninja op op, 2020-05-08 11:52:42

How to get last 10 records from MYSQL in reverse order?

How can I pull out the last 10 records from the table (for example ORDER BY ID, DESC LIMIT 10), but at the same time, so that they are in reverse order, for example:
10 last records in normal order:
1,2,3,4,5,6 ,7,8,9,10 Last
10 records in reverse order:
10,9,8,7,6,5,4,3,2,1

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
ninja op op, 2020-05-08
@kur4chyt

I solved it in the following way:

collect(Model::orderBy('id','desc')->take(10)->get())->reverse();

B
bkosun, 2020-05-08
@bkosun

SELECT * FROM (SELECT * FROM `table_name` ORDER BY `id` DESC LIMIT 10) AS `table_name` ORDER BY `id` ASC

F
FanatPHP, 2020-05-08
@FanatPHP

The easiest way is to reverse the order in php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question