sql - why is mysql not returning correct order for varchar of floats? -
i have column version varchar contains double values. when try latest (max) version incorrect results. when min, correct result.
how ordering of varchar columns containing double determined?
here content of table;
mysql> desc application; +---------+------------------+------+-----+---------+----------------+ | field | type | null | key | default | | +---------+------------------+------+-----+---------+----------------+ | id | int(11) unsigned | no | pri | null | auto_increment | | version | varchar(50) | yes | | null | | +---------+------------------+------+-----+---------+----------------+ 2 rows in set (0.01 sec) mysql> select * application; +----+---------+ | id | version | +----+---------+ | 1 | 0.0.0 | | 2 | 0.0.1 | | 3 | 0.0.2 | | 4 | 0.1.0 | | 5 | 0.1.1 | | 6 | 0.1.2 | | 7 | 1.0.0 | | 8 | 1.0.1 | | 9 | 1.1.1 | | 10 | 8.7.3 | | 11 | 10.29.0 | +----+---------+ 11 rows in set (0.00 sec) select max(version) application; +--------------+ | max(version) | +--------------+ | 8.7.3 | +--------------+ 1 row in set (0.00 sec) mysql> select version application -> order version desc -> limit 1; +---------+ | version | +---------+ | 8.7.3 | +---------+ 1 row in set (0.00 sec) mysql> select min(version) application; +--------------+ | min(version) | +--------------+ | 0.0.0 | +--------------+ 1 row in set (0.00 sec)
forget idea these floats. mysql sees them character strings because that's you've told it.
sorting character order, 8 largest, , 0 minimum, results correct.
if want mysql sort numerical order, give numerical fields. alternatively, right-align , zero-pad subfields - 08.07.03 less 10.29.00
Comments
Post a Comment