Skylight_lady Posted December 9, 2011 Share Posted December 9, 2011 I have a table with a price and ID. My totals are shown in the table below with the price ID: ID Price 504 4720.00 504 864.00 504 16571.84 Now, i am trying to write a mysql ststement that allows me to get the lowest price in the database from the table above e.g 864.00 SELECT MIN(price) AS TOTALLEAST FROM mytable WHERE ID = '504' LIMIT 1 The above sql statement is only give me the 16571.84 result. Why exactly is this? And whats the correct statement? Link to comment https://forums.phpfreaks.com/topic/252846-data-not-returning-the-correct-smallest-amount/ Share on other sites More sharing options...
Pikachu2000 Posted December 9, 2011 Share Posted December 9, 2011 What is the data type of the field? Link to comment https://forums.phpfreaks.com/topic/252846-data-not-returning-the-correct-smallest-amount/#findComment-1296326 Share on other sites More sharing options...
Skylight_lady Posted December 9, 2011 Author Share Posted December 9, 2011 Here it is: `price` varchar(10) NOT NULL DEFAULT '' Link to comment https://forums.phpfreaks.com/topic/252846-data-not-returning-the-correct-smallest-amount/#findComment-1296328 Share on other sites More sharing options...
Pikachu2000 Posted December 9, 2011 Share Posted December 9, 2011 Change it to a numeric data type. It's sorting alphabetically now, so the leading 1 in the number makes it the minimum value in the field. Link to comment https://forums.phpfreaks.com/topic/252846-data-not-returning-the-correct-smallest-amount/#findComment-1296335 Share on other sites More sharing options...
Skylight_lady Posted December 9, 2011 Author Share Posted December 9, 2011 Thank you. That explains it. I'm now using a Decimal datafield which sorts it out. Link to comment https://forums.phpfreaks.com/topic/252846-data-not-returning-the-correct-smallest-amount/#findComment-1296344 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.