{"id":120,"date":"2012-12-06T10:24:40","date_gmt":"2012-12-06T02:24:40","guid":{"rendered":"http:\/\/matnet.my\/blog\/?p=120"},"modified":"2012-12-06T10:25:38","modified_gmt":"2012-12-06T02:25:38","slug":"sort-mysql-varchar-column","status":"publish","type":"post","link":"https:\/\/matnet.my\/blog\/2012\/12\/sort-mysql-varchar-column\/","title":{"rendered":"Sort MYSQL varchar column"},"content":{"rendered":"<p>Salam.<\/p>\n<p>I need to sort a varchar column that contains letter and number. For example<\/p>\n<p>IC<br \/>\nG1000<br \/>\nG9090<br \/>\nG1200<br \/>\nG8900<br \/>\nG18790<br \/>\nG20110<\/p>\n<p>If we just sort by the IC number it will be like this:<\/p>\n<p>IC<br \/>\nG18790<br \/>\nG20110<br \/>\nG1000<br \/>\nG1200<br \/>\nG8900<br \/>\nG9090<\/p>\n<p>I want a result like this:<\/p>\n<p>IC<br \/>\nG1000<br \/>\nG1200<br \/>\nG8900<br \/>\nG9090<br \/>\nG18790<br \/>\nG20110<\/p>\n<p>So what i did, i just combine the function of SUBSTR and also +0<\/p>\n<p>Example : <strong>ORDER BY SUBSTR(IC,2)+0 ASC<\/strong><\/p>\n<p>Where substr function is to read the second letter and +zero is to make it sort faster then use a cast operator.<\/p>\n<p>Bye.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Salam. I need to sort a varchar column that contains letter and number. For example IC G1000 G9090 G1200 G8900 &hellip; <a href=\"https:\/\/matnet.my\/blog\/2012\/12\/sort-mysql-varchar-column\/\" class=\"more-link\">More <span class=\"screen-reader-text\">Sort MYSQL varchar column<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,3],"tags":[],"class_list":["post-120","post","type-post","status-publish","format-standard","hentry","category-bsd-nix","category-www","standard"],"_links":{"self":[{"href":"https:\/\/matnet.my\/blog\/wp-json\/wp\/v2\/posts\/120","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/matnet.my\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/matnet.my\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/matnet.my\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/matnet.my\/blog\/wp-json\/wp\/v2\/comments?post=120"}],"version-history":[{"count":3,"href":"https:\/\/matnet.my\/blog\/wp-json\/wp\/v2\/posts\/120\/revisions"}],"predecessor-version":[{"id":123,"href":"https:\/\/matnet.my\/blog\/wp-json\/wp\/v2\/posts\/120\/revisions\/123"}],"wp:attachment":[{"href":"https:\/\/matnet.my\/blog\/wp-json\/wp\/v2\/media?parent=120"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/matnet.my\/blog\/wp-json\/wp\/v2\/categories?post=120"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/matnet.my\/blog\/wp-json\/wp\/v2\/tags?post=120"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}