How to have reverse order output on MYSQL database

前端 未结 6 815
無奈伤痛
無奈伤痛 2020-12-11 19:33

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,

相关标签:
6条回答
  • 2020-12-11 20:05

    write below query to retrive data

    SELECT * FROM `table_name` order by id desc
    

    it will retrieve data from table in descending order

    0 讨论(0)
  • 2020-12-11 20:08
    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

    0 讨论(0)
  • 2020-12-11 20:09

    Change the ORDER BY statement

    • from ORDER BY col or ORDER BY col ASC or to ORDER BY col DESC
    • from ORDER BY col DESC to ORDER BY col ASC
    0 讨论(0)
  • 2020-12-11 20:13

    MySQL 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

    0 讨论(0)
  • 2020-12-11 20:17

    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

    0 讨论(0)
  • 2020-12-11 20:20

    Sort using DESC ORDER BY.

    SELECT * FROM <TABLE> ORDER BY <COLUMN> DESC
    
    0 讨论(0)
提交回复
热议问题