.:HyPeX:. Posted January 16, 2015 Share Posted January 16, 2015 Hello, how can i order a table by a column? I can already retrive the value while selecting with "ORDER BY", but that wont change the table rows. How can i actually change the table rows? Greetz HyPeX Link to comment
Gallardo9944 Posted January 16, 2015 Share Posted January 16, 2015 Something like this should do it: ALTER TABLE tops ORDER BY time ASC; (Change to DESC to switch sorting) Link to comment
.:HyPeX:. Posted January 16, 2015 Author Share Posted January 16, 2015 Something like this should do it: ALTER TABLE tops ORDER BY time ASC; (Change to DESC to switch sorting) That didnt worked... http://www.w3schools.com/sql/trysql.asp ... t_distinct Link to comment
novo Posted January 16, 2015 Share Posted January 16, 2015 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
Gallardo9944 Posted January 16, 2015 Share Posted January 16, 2015 table.sort is much slower than mysql sorting. Doing that in your queries won't affect performance, tested with 3000 rows with 40 columns. Link to comment
.:HyPeX:. Posted January 16, 2015 Author Share Posted January 16, 2015 Actually, i like the simplicity of mysql sorting over table.sort, rather than by its performance. I'll do a live test later. Thanks guys. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now