Reputation: 11
In my database there are 5 values: 50, 75, 95, 125 and 200. When I query the minimum value I get 125, but I should get 50.
Here is my code:
$result_upTICKET = mysql_query("SELECT ID, EID, COMMISSION, MIN(PRICE) as PRICE FROM `tickets` WHERE EID='$EID_UPcoMing' AND STATUS='1'");
while($row_upTICKET = mysql_fetch_array($result_upTICKET))
{
$PRICE_upTICKET= $row_upTICKET['PRICE'];
$COMMISSION_upTICKET= $row_upTICKET['COMMISSION'];
}
What did I get wrong?
Upvotes: 0
Views: 84
Reputation: 460
Please execute your query like,We need to convert into interger
mysql_query("SELECT ID, EID, COMMISSION, MIN(CONVERT(PRICE, SIGNED INTEGER)) as PRICE FROM tickets
WHERE EID='$EID_UPcoMing' AND STATUS='1'");
Upvotes: 0
Reputation: 7294
you are using where
condition also. It filters rows first then apply/Select
columns
and min
. I am sure that your where condition pull out row with price 50 and that's why min is coming as 125 instead of 50
Upvotes: 0
Reputation: 114
Try this one
SELECT ID, EID, COMMISSION, PRICE FROM `tickets` WHERE EID='$EID_UPcoMing' AND STATUS='1' ORDER BY PRICE ASC LIMIT 1
Upvotes: 1