When I do this query from PHP:
$result = mysql_query("SELECT armor_key, MAX(high_bid), value_full FROM armor WHERE armor_status='2' GROUP BY high_bid DESC LIMIT 3");
I don't seem to get the data for high_bid itself... It's probably a simple solution; how do I specify that I also want to get the high_bid value? I've tried removing and replacing the GROUP BY, but when I don't use it, I get a MySQL error, and when I enter another column like value_full, I get unwanted results... Can anyone help?
MySQL query results on MAX() and GROUP BY
Moderator: General Moderators
Afaik you can only have columns in your select clause if they are in the group by clause (or if they are in an aggregate function)
Btw, if you group by high_bid you will end up with rows that have high_bid = MAX(high_bid)...
Meaby you want to use the "WITH ROLLUP" option.. (More info http://dev.mysql.com/doc/mysql/en/group ... fiers.html)
Btw, if you group by high_bid you will end up with rows that have high_bid = MAX(high_bid)...
Meaby you want to use the "WITH ROLLUP" option.. (More info http://dev.mysql.com/doc/mysql/en/group ... fiers.html)
Code: Select all
SELECT high_bid, MAX(high_bid) AS max_bid, armor_key, value_full
FROM armor
GROUP BY high_bid, armor_key, value_full