I have a table with a column which can contain: "kldr", "bgg" or an integer.
Now i want a query with the result in the following order:
1. kldr
2. kldr
3. bgg
4. bgg
5. 1
6. 2
7. 3
8. etc.
Can anyone help me out? My current query is obvious not working.
SELECT *
FROM table
WHERE column_x='$value_x'
ORDER BY column_y LIKE '%kldr%' ASC, LIKE '%bgg%' ASC, floor ASC
You can use a CASE
expression in the ORDER BY
clause:
SELECT *
FROM table
WHERE column_x='$value_x'
ORDER BY CASE WHEN column_y LIKE '%kldr%' THEN 1
WHEN column_y LIKE '%bgg%' THEN 2
ELSE column_y + 2
END