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. 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 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 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? 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. 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
Archived
This topic is now archived and is closed to further replies.