By default, the ORDER BY clause will sort data using alphanumeric sorting. But there is a trick by using the MySQL field(str,str1,str2,str3...) function to give a different order to the values in the columns. The function finds the position of str in the list of strings str1, str2, str 3...
Here is an example on how you can combine the field function with the ORDER BY clause:
ORDER BY field(`column_name`, 'One', 'Two', 'Three', 'Four', 'Five')The above code will sort the data according to the column values One, Two, Three, Four, Five.
No comments:
Post a Comment