Skip to content
Advertisement

How to sort values in columns and update table?

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.

Table looks like that:

I want to get something like that:

So I need to sort “id” and “name” columns.

I use following statement to sort values of “name” column:

But how can I sort the values of id column and save changes in table? Please, help.

Advertisement

Answer

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

  2. copy the data, sorted, into games2

  3. drop or move the old table

  4. rename new table to old name

These steps will result in what you want.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement