0

I've got a set of rows in a database that have counts for something specific. When I do my query:

SELECT * FROM table ORDER BY field ASC LIMIT 1

The results I get are incorrect, because it sorts based on the first number apparently.

So the results that are supposed to be:

1
2
3
4
5
10

End up being:

1
10
2
3
4
5

How can I adjust my query so that the field is returned in the proper order? I'm not sure how to word it to search to get the proper answer.

MrTechie
  • 1,797
  • 4
  • 20
  • 36

1 Answers1

1

There's a trick I learned long time ago that works on even strings of alphabet as well which is.

SELECT * FROM table 
ORDER BY LENGTH(field) ASC, field ASC

learn this trick and you're now a master of ORDER BY :D

Tin Tran
  • 6,194
  • 3
  • 19
  • 34