I have a basic write to and retrieve SQL database PHP "thing" and I want to have the output in descending order. How do I do that?
For example, the last entry is shown first, then the entry before that, then the entry before that, etc. The first entry ever is last.
The REVERSE() function reverses a string and returns the result.
The MySQL ORDER BY Keyword The ORDER BY keyword sorts the records in ascending order by default. To sort the records in descending order, use the DESC keyword.
To roll back the current transaction and cancel its changes, you use the ROLLBACK statement. To disable or enable the auto-commit mode for the current transaction, you use the SET autocommit statement.
At any point, you may undo all of the statements for the transaction by entering the following SQL statements: ROLLBACK; 5.
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.
Change the ORDER BY
statement
ORDER BY col
or ORDER BY col ASC
or to ORDER BY col DESC
ORDER BY col DESC
to ORDER BY col ASC
Sort using DESC
ORDER BY
.
SELECT * FROM <TABLE> ORDER BY <COLUMN> DESC
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With