Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

SQL MIN() not returning the minimum value

New Here ,
Nov 06, 2011 Nov 06, 2011

This is my code;

$SQLx = "SELECT MIN(price_from) AS minimumprice FROM AN_pricetable WHERE accomm_id = " . $db_field['accomm_id'];

$resultx = mysql_query($SQLx);

$pricefrom = mysql_result($resultx,$i,'minimumprice');

if ($pricefrom == 0){

  $pricefrom = "TBC";}

But for some reason it is not returning the minimum 'price_from' value. For example several rows in the table have the same 'accomm_id', and their values in the 'price_from' field are: 8, 12, 50 and 7, but the SQL is returning 12 as the MIN. What am I doing wrong here?

Thanks

TOPICS
Server side applications
622
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Nov 06, 2011 Nov 06, 2011

What is the datatype of price_from?  If it's a string (char) type, then 12 would be the lowest value.

Translate
LEGEND ,
Nov 06, 2011 Nov 06, 2011

What is the datatype of price_from?  If it's a string (char) type, then 12 would be the lowest value.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 06, 2011 Nov 06, 2011
LATEST

Ahhhh it was varchar, now its int and works. Thank you!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines