I want to sort all data in custom manner with conditional statement. Firstly, I will check if column1 & column1 are same. If they are same then I will compare based on column3.
Example
| id | total_score | mcq_score |
|---|---|---|
| 1 | 50 | 30 |
| 2 | 50 | 40 |
| 3 | 50 | 20 |
Expected output
| id | total_score | mcq_score |
|---|---|---|
| 2 | 50 | 40 |
| 1 | 50 | 30 |
| 3 | 50 | 20 |
Specify both columns in ORDER BY. If the values in first column have a tie, the second column is considered (and so on):
ORDER BY total_score DESC, mcq_score DESC
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With