I need help with it.
I have a table with the next data
|---id---|-----name-----|--value--|
| 1 | Alex | 300 |
| 2 | John | 800 |
| 3 | Mary | 0 |
| 4 | Carl | 100 |
| 5 | Jesus | 0 |
| 6 | Aron | 0 |
To order the table by value
, I'm using:
SELECT * FROM table ORDER_BY value DESC;
But sometimes I get a result like:
|---id---|-----name-----|--value--| | 2 | John | 800 | | 1 | Alex | 300 | | 4 | Carl | 100 | | 5 | Jesus | 0 | | 3 | Mary | 0 | -- ! | 6 | Aron | 0 |
I want to order the table with a condition: "if value is not 0 order by value and if value is 0 order by id" to get:
|---id---|-----name-----|--value--|
| 2 | John | 800 |
| 1 | Alex | 300 |
| 4 | Carl | 100 |
| 3 | Mary | 0 |
| 5 | Jesus | 0 |
| 6 | Aron | 0 |
How can I do it?