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

Custom sort By ON Fields Mysql

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')
ORDER BY FIELD(id,'109k7','s3x6','sxmns','wt57')

Back to top

Related Pictures

Tags for Custom sort By ON Fields Mysql

Recent comments

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