Here's a quick tip at sorting VARCHAR type data in mysql database with values in a column.
With the default sort, it would look something like below:
mysql> SELECT column FROM table_name ORDER BY column; column ====== 100 1000 10000 200 2000 20000 ...
Now with "... ORDER BY column+0", I get it sorted right:
mysql> SELECT column FROM table_name ORDER BY column+0; column ====== 100 200 1000 2000 10000 20000 ...
This is a quick fix instead of sorting to CAST operator.












S=cuder=O
Muchas gracias!!
No sabia como resolverlo
That is kooo
I have tried to finding a solution to sort TEXT so this Is gr8 and use Full Thanks buddy
I've searched all over the
I've searched all over the internet to find some solution for varchar field with mixed numbers and text and it works perfect! (Fortunately all my records in this field starts with number and text is after)
Big THX!
NEED HELP SORTING VARCHAR
hayz, i tried the syntax above but it seems doesn't work in numbers + alphabet. hayz. it gives me a headache.
Sorting VARCHAR
Very useful solution, tanks for the trick.
but this fails when the data
but this fails when the data in the varchar field is a combination of alphabet and numeric
Yarr, using varchar fields
Yarr, using varchar fields to store numerical data is already a clear indicator that your database design is flawed.
I haven't tried it yet but
I haven't tried it yet but this might be useful for situations like mine where I have varchar fields with filenames that are numbered such as filename_01.jpg, filename_02.jpg, etc. I don't know if this is what I need, but it doesn't mean the database is flawed necessarily.
Post new comment