M
M
Messi2018-06-15 16:29:23
MySQL
Messi, 2018-06-15 16:29:23

Sorting a textbox as a number and as a string at the same time?

Hello! I'm displaying data from a table in a GridView. There is a field "Number" - text type. Can you please tell me how to sort this field in the Mysql database at the same time as a number and a string. For example:
1, 2, Field, Number, 10, 15
And get after sorting
1, 2, 10, 15, Number, Field

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ice, 2018-06-15
@FitTech

There is no natural sort in SQL, only two options ASC / DESC
SELECT * FROM table ORDER BY value ASC

R
Rsa97, 2018-06-15
@Rsa97

If all numeric values ​​are non-negative integers, then

ORDER BY IF(`val` REGEXP('^[0-9]+$'), LENGTH(`val`), 100), `val`

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question