How to sort values in columns and update table?

前端 未结 7 2549
花落未央
花落未央 2020-12-05 15:28

I\'m completely new to sql and can\'t do that myself. So I need your help. I want to sort values in column and then save changes. But I don\'t know how to do that.

T

7条回答
  •  被撕碎了的回忆
    2020-12-05 15:35

    You would have to use a second table

    1. create a new table games2 with the same structure as your games table, making sure the ID is auto-incrementing

      CREATE TABLE `games2` LIKE `games`;
      
    2. copy the data, sorted, into games2

      INSERT INTO `games2` (`Name`, `SomeDescription`) SELECT `Name`, `SomeDescription` FROM `games` ORDER BY `Name`
      
    3. drop or move the old table

      -- DROP TABLE `games`;
      -- or
      RENAME TABLE `games` TO `games1`;
      
    4. rename new table to old name

      RENAME TABLE `games2` TO `games`;
      

    These steps will result in what you want.

提交回复
热议问题