How to sort the MySql Database?

后端 未结 2 2022
陌清茗
陌清茗 2021-01-24 01:48

I have stored various records in the MySql database \"orkut\". Now I want to sort that database through a java program. I have connected to the database through the jdbc driver.

相关标签:
2条回答
  • 2021-01-24 02:37

    Don't try to sort this through Java--you'll kill yourself trying. SQL has an order by clause that does exactly this. Here's the SQL:

    select
        number,
        sr_no
    from
        tbl
    order by
        number desc
    

    Also note that you cannot have a permanently sorted database. The way that the data is stored does not lend itself to being stored in whatever order you choose. You should never count on the order of a database to be the same, unless you use an order by in your query.

    0 讨论(0)
  • 2021-01-24 02:48

    as eric told you can't have a permanently sorted database. But if you want to execute this query on a large dataset very frequently then you can do indexing supported by various database.

    It will speedup your searching and sorting for a particular key.

    0 讨论(0)
提交回复
热议问题