Reputation:
i think this is really simple. I just want to return an select that has a custom order.
The result from my select is this.
I want the select to return this order
The ideal is that no matter the result Home
is always first and Logout
is always last. And everything in the middle is ordered asc. Any how would be fantastic!
Upvotes: 1
Views: 49
Reputation: 571
SELECT *
FROM yourTable
ORDER BY IF(name = 'home', -1, (IF(name = 'logout', 1, 0))), name
Upvotes: 0
Reputation: 2856
SELECT *
FROM yourTable
ORDER BY CASE WHEN name = 'Home' THEN 1
WHEN name = 'Logout' THEN 3
ELSE 2
END ASC,
name ASC
Upvotes: 1
Reputation: 166466
How about
SELECT *
FROM MyTable
ORDER BY
CASE
WHEN ColumnValue = 'Home' THEN -1
WHEN ColumnValue = 'Logout' THEN 1
ELSE 0
END,
ColumnValue
Upvotes: 0