andz Posted December 13, 2008 Share Posted December 13, 2008 I have stumbled on a problem with regards to selecting the highest value from a table. I have this data on my table:: price 1,000,000.00 3,000,000.00 500.00 23.00 5,234,234.53 I used SELECT * FROM `table_name` ORDER BY `price` DESC; but instead of returning the highest value, that's not what happened. price field is varchar(20) any possible query codes would be accepted. thank you. Quote Link to comment https://forums.phpfreaks.com/topic/136794-select-highest-value/ Share on other sites More sharing options...
corbin Posted December 13, 2008 Share Posted December 13, 2008 First off, use MAX if you want the 1 highest value. Second, numerical comparisons and string fields do not go well. Use float, or better yet, decimal for the field. Example: SELECT MAX(price) FROM table_name; Quote Link to comment https://forums.phpfreaks.com/topic/136794-select-highest-value/#findComment-714441 Share on other sites More sharing options...
borabora12 Posted December 13, 2008 Share Posted December 13, 2008 instead of making the field named price varchar(20) you should make it decimal(18,2) in that case it will work using the DESC function. in decimal(18,2) the 2 represents how many spaces from the right the decimal will be placed from. And 18 represents how many digits come left of the decimal point. hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/136794-select-highest-value/#findComment-714618 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.