Answer the question
In order to leave comments, you need to log in
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
I solved it in the following way:
collect(Model::orderBy('id','desc')->take(10)->get())->reverse();
SELECT * FROM (SELECT * FROM `table_name` ORDER BY `id` DESC LIMIT 10) AS `table_name` ORDER BY `id` ASC
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question