0

i have such a sql query:

SQL:

SELECT *
FROM statistic_table
ORDER BY lot_oldness_sum,
         lot_oldness_sum2 ASC

and I'm getting result

212 22 224 225

I need to get by smallest digit to biggest in such a way: 22 212 224 225

I've also made the another query:

SQL:

SELECT *
FROM statistic_table
ORDER BY MAX(lot_oldness_sum),
         MAX(lot_oldness_sum2) ASC

but still the same.

NikuNj Rathod
  • 1,663
  • 1
  • 17
  • 26
  • Possible duplicate of https://stackoverflow.com/questions/8557172/mysql-order-by-sorting-alphanumeric-correctly – Syscall Mar 27 '18 at 12:59
  • 1
    Possible duplicate of [MySQL 'Order By' - sorting alphanumeric correctly](https://stackoverflow.com/questions/8557172/mysql-order-by-sorting-alphanumeric-correctly) – Dave Mar 27 '18 at 13:00
  • And if it’s always numeric data then store it as numeric and not as text in the database. – Sami Kuhmonen Mar 27 '18 at 13:04

1 Answers1

0
$sql = "SELECT * FROM statistic_table ORDER BY LENGTH(lot_oldness_sum), lot_oldness_sum ASC"

This one worked for me.