0

I want to sort data like below in mysql

unsorted data

aa 1 2 f 11 3 df 10

Sorted data(desired output)

1 2 3 10 11 aa df f

manish511
  • 1
  • 1
  • A simple ORDER BY will fetch you the desired result https://dev.mysql.com/doc/refman/5.7/en/sorting-rows.html – Wilson Mar 26 '18 at 11:41
  • 1
    So you have the same column containing numbers and characters? – davidbaumann Mar 26 '18 at 11:41
  • 1
    is each number / string in a row or is "aa 1 2 f 11 3 df 10" a string ? pls show your table structure – Bernd Buffen Mar 26 '18 at 11:42
  • 1
    @Wilson: you are wong because it would return the data as `1 10 11 2 3 aa df f` and not as the desired output. What is needed here is called `natural sort`. As far as i know MySQL doesn't provide any build-in solution for this. There are a lot of ways with that you can do it but you need to work with a few tricks. You might look at [this](https://stackoverflow.com/questions/8557172/mysql-order-by-sorting-alphanumeric-correctly). – Fabian S. Mar 26 '18 at 11:52
  • Possible duplicate of [MySQL 'Order By' - sorting alphanumeric correctly](https://stackoverflow.com/questions/8557172/mysql-order-by-sorting-alphanumeric-correctly) – Raymond Nijland Mar 26 '18 at 11:55
  • So you have the same column containing numbers and characters? – davidbaumann Yes – manish511 Mar 26 '18 at 12:52

0 Answers0