G
G
generate2020-11-13 08:50:15
MySQL
generate, 2020-11-13 08:50:15

How to properly sort multiple ORDER BY DESC conditions?

SELECT * FROM `serial` ORDER BY `serial`.`season` DESC, `serial`.`episode` DESC LIMIT 10

The first parameter is normal, but the second parameter is not in numerical order for some reason. How to fix it ?
5fae1e933ec88917110837.jpeg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2020-11-13
@generate

Most likely, the field has a text type, not a numeric type, which is why it is sorted as text.
Use Explicit Conversion

ORDER BY ... CAST(`serial`.`episode` AS UNSIGNED) DESC
Of course, the index will not work with such sorting.

D
Dr. Bacon, 2020-11-13
@bacon

Probably because episode is not a numeric type?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question