Reverse Query Result

I use the following query to get the last 10 results of my database, but I need them to not be in descending order. Anyway, can I accomplish this with a request, or do I need to process it in php? Thank you for your help.

SELECT * FROM MSG ORDER BY id DESC LIMIT 0,10
+5
source share
4 answers

Try the following to solve the problem.

SELECT * FROM (SELECT * FROM MSG ORDER BY id DESC LIMIT 10) AS RequiredLimit ORDER BY id ASC
+4
source

SELECT * FROM (SELECT * FROM MSG ORDER BY id DESC LIMIT 0.10) ORDER BY id - should work

+4
source

mysql, , php array_reverse() .

+3

While using a subquery is one of the answers, I find it more optimal to execute two queries than a subquery or subquery. Reduces overhead - correct me if I am wrong.

I would suggest:

$row_offset = get_result("SELECT COUNT(*) FROM MSG;") - 10;

$rows = get_result("SELECT * FROM MSG LIMIT " . $row_offset . ", 10;");

Assuming (of course!) That get_results () is a custom function that executes a query and returns data from a table.

+1
source

All Articles