27
Jul/090
Jul/090
SQL Select query with a predefined last entry
The task was to create a SELECT query on a table with titles grouped alphabetically by name, but a certain name must (if found) always stay at the end.
This is like the selecting of categories on ebay.com where the categories are arranged by name but the category “Other” must have the last place.
The solution I found:
assume the table is called categories and the column name is cat_name. The db engine is MYSQL.
SELECT cat_name FROM categories ORDER BY FIND_IN_SET(cat_name, 'Other'), cat_name
It seems to work properly.
