avvllvva Posted March 21, 2009 Share Posted March 21, 2009 Hi, I needs help in following Mysql issue. I have a table of two columns 'col_code(varchar)' , 'col_num(bigint)'. For more clarification I'm giving sample datas to the table col_code col_num AG-123 123 AG-88 88 EX-16 16 EX-220 220 AG-10 10 I needs to display the datas in following order :- AG-10, AG-16, AG-123, EX-16, EX-220 ie; first order by Alabetical and then numerical. Is it possible with these two columns. If yes, how can I write the sql statement with the order clause .. ?? Please help...........Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/150448-solved-order-by-two-columns-of-different-types-in-mysql/ Share on other sites More sharing options...
Maq Posted March 21, 2009 Share Posted March 21, 2009 This should give you the order the way you want it: SELECT * FROM table ORDER BY col_code Quote Link to comment https://forums.phpfreaks.com/topic/150448-solved-order-by-two-columns-of-different-types-in-mysql/#findComment-790141 Share on other sites More sharing options...
sasa Posted March 21, 2009 Share Posted March 21, 2009 ... ORDER BY SUBSTRING_INDEX(col_code, '-', 1), col_number Quote Link to comment https://forums.phpfreaks.com/topic/150448-solved-order-by-two-columns-of-different-types-in-mysql/#findComment-790189 Share on other sites More sharing options...
redarrow Posted March 21, 2009 Share Posted March 21, 2009 link for SUBSTRINGINDEX http://www.java2s.com/Tutorial/MySQL/0460__String-Functions/SUBSTRINGINDEXstrdelimcountReturnsthesubstringfromstringstrbeforecountoccurrencesofthedelimiterdelim.htm does this function also show the results alphabetically? Quote Link to comment https://forums.phpfreaks.com/topic/150448-solved-order-by-two-columns-of-different-types-in-mysql/#findComment-790190 Share on other sites More sharing options...
avvllvva Posted March 22, 2009 Author Share Posted March 22, 2009 ... ORDER BY SUBSTRING_INDEX(col_code, '-', 1), col_number Thanks.. Its worked out. Quote Link to comment https://forums.phpfreaks.com/topic/150448-solved-order-by-two-columns-of-different-types-in-mysql/#findComment-790731 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.