Reputation: 79
There is one table called projects with their details. projects
id | status |name
1 | Red | Prj1
2| Amber | Prj2
3| Green | Prj3
4| RED | Prj4
5|Completed | Prj5
6|Amber | Prj6
7|Green | Prj7
5|Completed | Prj8
Using mysql-can I arrange in specific order. Result needed show all projects in Red at first place than Green and Amber after that completed
Thanks in advance
Upvotes: 0
Views: 42
Reputation: 17289
SELECT *
FROM projects
ORDER BY FIND_IN_SET(status,'Completed,Amber,Green,Red') DESC
Upvotes: 1
Reputation: 1269783
Just use an expression in the order by
:
order by (case when status = 'red' then 1 when status = 'green' then 2 else 3 end)
Upvotes: 1