
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:
We can use field_functions from mysql for custom sort or Can use CASE, IF,ELSE functionalities in mysql.
i.e:
ORDER BY CASE
WHEN `col` = 'item' THEN 1
WHEN `col` = 'thing' THEN 2
WHEN `col` = 'stuff' THEN 3
WHEN `col` = 'boom' THEN 4
ELSE 5
END
Example:-
1)
SELECT link_path,mlid FROM `rts1_menu_links` order by CASE WHEN link_path="photos/upload" THEN 1 ELSE 5 END,link_path DESC
2)select id from products where id in (4,5,6,7,8,9) order by field(id,4,7,6,5,9,8)
SELECT id, start_date FROM iddt WHERE id IN
('109k7','s3x6','sxmns','wt57')
InderSingh.com v1.2
(May 22, 2012)
Recent comments
17 weeks 1 day ago
17 weeks 1 day ago
17 weeks 1 day ago
1 year 16 weeks ago
1 year 16 weeks ago
1 year 16 weeks ago
1 year 32 weeks ago
1 year 33 weeks ago
1 year 35 weeks ago
1 year 39 weeks ago