Reputation: 1031
Please I have a field value (type text) that contains some values (text and also some int or float values).
So I want to select only the float and integers values and order theme by the field value.
For the moment I can get floats separately but the problem is that in result I get theme ordered in a text format and not in float or integer format (and it's normal I guess). Example :
33
33358
80
88000
90
99
Please masters, How could I tell my query to consider results as floats and not text and get instead this result :
33
80
90
99
33358
88000
Thanks in advance
Upvotes: 1
Views: 6225
Reputation: 4862
Storing mixed values in a field with type text is not a good idea. If you want to make sorting and filtering on the field, I would recommend to use them as separated fields - text, int, float, etc.
If you go deep as database administrator, it will have negative performance.
Upvotes: 1
Reputation: 2291
cast VALUE to float/int format when you select that variable in your query and then order the result set by that column.
eg./ SELECT CAST(value as decimal(10,5)) AS customname FROM tablename order by customname
remember, you can cast to whatever you want.
Upvotes: 0
Reputation: 4830
ORDER BY field * 1
Or
ORDER BY CAST(field as DECIMAL(10,5))
Both should do the same thing but the first is easier/quicker to write.
Upvotes: 14