
Skip to: site menu |main content
Welcome to my personal site. If You have any question or suggestion please feel free to contact me from contact page.
For sorting in ascending order numbers which are written in text or characters:-
mysql> select number from (table) order by number;
+--------+
| number |
+--------+
| 1 |
| 10 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
| 7 |
| 8 |
| 9 |
+--------+
Use this:
mysql> select number from (tablename) order by (number+0);
+--------+
| number |
+--------+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
| 7 |
| 8 |
| 9 |
| 10 |
+--------+
The (field + 0 ) converts the text/character in the field into an integer.
To sort results in a particular predefined order list. We can Just use the FIELD function:
SELECT * FROM task_list
ORDER BY FIELD(priority, 'High', 'Normal', 'Low', 'The Abyss');
Recent comments
16 weeks 4 days ago
16 weeks 4 days ago
16 weeks 4 days ago
1 year 16 weeks ago
1 year 16 weeks ago
1 year 16 weeks ago
1 year 31 weeks ago
1 year 33 weeks ago
1 year 34 weeks ago
1 year 39 weeks ago