How to reverse order output of a MySQL query
Solution 1:
Use:
SELECT field_name
FROM table_name
ORDER BY id DESC
By default, MySQL will show results in ascending order. If you want to show them in reverse order, use ORDER BY field_name DESC
.
You can use id or date as the field name.
Solution 2:
Sort using DESC
ORDER BY
.
SELECT * FROM <TABLE> ORDER BY <COLUMN> DESC
Solution 3:
Change the ORDER BY
statement
- from
ORDER BY col
orORDER BY col ASC
or toORDER BY col DESC
- from
ORDER BY col DESC
toORDER BY col ASC
Solution 4:
If there's an auto increment field, you order by that field, descending.
SELECT "column_name"
FROM "table_name"
[WHERE "condition"]
ORDER BY "column_name" [ASC, DESC];
That's from ORDER BY Clause - Sort Data In SQL.