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.

Advertisements

Contact me to place your Ads Here..

Powered by Drupal, an open source content management system

Syndicate

Syndicate content

Mysql Sorting Field function ,Number And character fields Mysql

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');

Back to top

Related Pictures

Tags for Mysql Sorting Field function ,Number And character fields Mysql

Recent comments

InderSingh.com v1.2
(May 18, 2012)