A
A
Alex Ponomarev2020-06-16 18:33:48
SQL
Alex Ponomarev, 2020-06-16 18:33:48

Sorting goes only by the first character, how to fix it?

$rez = mysqli_query($database_connect, "SELECT * FROM `mytable2` ORDER BY `3` DESC");

in column 3 there are numbers from 1 to 100. and for example the number 5 is higher in the search than 49. Sorting goes only by the first character, how to fix this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2020-06-16
@rusindex

Column type - CHAR (VARCHAR)?

... ORDER BY col + 0 DESC

... ORDER BY CAST(col AS int)  DESC

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question