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?
Eg. last entry is shown first,
write below query to retrive data
SELECT * FROM `table_name` order by id desc
it will retrieve data from table in descending order
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 put 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 DESCORDER BY col DESC to ORDER BY col ASCMySQL General Query Syntax for Select:
SELECT field1, field2,...fieldN FROM table_name
[WHERE Clause][GROUP BY]
[ORDER BY][LIMIT]
Example Query 1:
SELECT id,first_name,last_name,email FROM users ORDER BY first_name desc// In this case you can only fetch data by = id,first_name,last_name,email
Example Query 2:
SELECT * FROM users ORDER BY first_name desc // In this case all fields will be selected
Note: ORDER BY ASC = Data will sort by Ascending Order & ORDER BY DESC = Data will sort by descending Order
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 http://www.1keydata.com/sql/sqlorderby.html
Sort using DESC ORDER BY.
SELECT * FROM <TABLE> ORDER BY <COLUMN> DESC