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? Quote Link to comment 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? Quote Link to comment 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 '' Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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.