I am facing a problem to sort order follow the number in the column data in SQL. For example, the column data include are 100-1/1/1 ABC , 100-1/1/3 CDE, 100-1/1/2 CDE. I want to sort in order number result follow like 100-1/1/1 ABC ,100-1/1/2 CDE and 100-1/1/3 CDE.
Below is sample table data, table name called test2
:
id | name |
4 200 DAVID
1 100 JOHN
3 100-1 SHAWN
9 100-1/1 PETER
11 100-1/1/1 ALVIS
12 100-1/1/10 ROBERT
2 100-1/1/11 HENRY
13 100-1/1/3 PIRES
14 100-2 CRISTY
20 100-1/2 BILLY
32 100-1/2/1 JIOUS
I am using MySQL version, and write the SQL query is SELECT * FROM test2 order by name
, but it cannot sort the number correctly.
Actually I want the expected result is like below the table:
id | name |
1 100 JOHN
3 100-1 SHAWN
9 100-1/1 PETER
11 100-1/1/1 ALVIS
13 100-1/1/3 PIRES
12 100-1/1/10 ROBERT
2 100-1/1/11 HENRY
20 100-1/2 BILLY
32 100-1/2/1 JIOUS
14 100-2 CRISTY
4 200 DAVID
This is my real scenario for sort the name:
Hope someone can guide me to solve this problem. Thanks.