Jump to content

Ordering a mysql table


.:HyPeX:.

Recommended Posts

As specified here, an "ALTER TABLE ORDER BY" statement exists in the syntaxes accepted by MySQL so w3schools syntax checker might be slightly outdated.

So, as Gallardo stated above, you should do it as follows: (reference)

  
ALTER TABLE tablename ORDER BY columnname; 
ALTER TABLE tablename ORDER BY column1 ASC, column2 DESC; 
  

Though, at the beginning, the sort will begin to drift after additional INSERTs and DELETEs. Rows that will sorted will remain in their order, but new rows will be placed at the end.

And well, in case this causes any grand dilemma to you, you could simply sort the rows when fetching the table's results. (table.sort)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...