MySQL Sorting Rules Explained
MySQL offers a variety of sorting rules, as detailed below:
- ASC (ascending): arrange in alphabetical or numerical order from the lowest to the highest.
- DESC: Arrange in descending order based on alphabetical or numerical value.
- UTF8_BIN: Sort based on the binary values of the strings, suitable for distinguishing between uppercase and lowercase letters as well as accent symbols.
- UTF8_GENERAL_CI: Sorts according to the general sorting rules of strings, without distinguishing between uppercase and lowercase letters or accent marks.
- UTF8_UNICODE_CI: Sort according to the Unicode sorting rules of the string, regardless of case and diacritics.
In the ORDER BY clause, you can control the way data is sorted by specifying the sorting order. For example, you can use ORDER BY column_name ASC to sort the data in the column_name column in ascending order. By default, MySQL uses the UTF8_GENERAL_CI sorting rule.