SQL for ordering by number - 1,2,3,4 etc instead of 1,10,11,12
When we use
ORDER_BY registration_no ASC
get...
1
101
102
103
104
105
106
107
108
109
11
110
Etc…
Using 'order by len(registration_no)' we will get
1
11
101
102
10
104
105
106
107
108
119
Etc...
This is particularly useful when the column might contain non-numeric values.
Note: in some databases, the function to get the length of a string might be called length()
instead of len()
.
Comments
Post a Comment