sql - Max Function of Mysql not returning maximum value of coloumn. Order by limit also not working -
i have table structure follows:
history_card +----+-----------+---------+--------------+ | idhistory_card |equipment_id | sr_num | +----+-----------+---------+--------------+ | 1 | du 201 | 9 | | 2 | du 201 | 2 | | 3 | du 201 | 12 | | 4 | ext 99 | 10 | | 5 | ext 99 | 13 | | 6 | ext 99 | 7 | | 7 | ext 99 | 9 | +----+-----------+---------+--------------+
i return maximum value of coloumn(sr_num) particular euipment_id. eg. equipment_id = du 201 , maximum value 12 below mentioned queries returning wrong value i.e 9 equipment_id = ext 99 , maximum value 13 below mentioned queries returning wrong value i.e 9 . have searched lot in internet on manual of no use till now.kindly help!
queries follows
select * new_schema.history_card equipment_id = 'du 201' order sr_num desc limit 1
2 query tried
select max(sr_num) new_schema.history_card equipment_id='du 201';
the max()
operation on string value behave according string comparison rules, i.e. "9" > "10"
.
the answer change table definition:
alter table history_card modify sr_num int;
then, run query again.
Comments
Post a Comment