I am doing a sorting on a table to show the records with status having 3 first then status having 4 and then 1.
in current table this is the output
id status
1 3
2 4
3 4
4 3
5 1
now when i apply the query
select * from table order by model.status desc
the output is:
id status
2 4
3 4
1 3
4 3
5 1
what i want actually the below output. first with status 3 then with status 4 and then with status 1. How to achieve the below output
id status
1 3
4 3
2 4
3 4
5 1
instead of a magic 9999999 number, you can use ~0, which represents the maximum possible value for big int… should be enough 😉
other solution, without any magic number
which will sort by a “boolean” (0 or 1 in DB) first, then by status