Friday, 16 April 2010

What is order by length in mysql?

+------+
| code |
+------+
| A10  |
| A20  |
| A5   |
| A6   |
| A7   |
| A8   |
| A9   |
+------+

You can query like this:
mysql> select * from table order by length(code), code;

+------+
| code |
+------+
| A5   |
| A6   |
| A7   |
| A8   |
| A9   |
| A10  |
| A20  |
+------+
  
Cheers! 

No comments:

Post a Comment