OK - I get no errors from the above, but no rows either. These examples are from phpMyIDE, but I get the same results in phpMyAdmin.
For references:
select item_id, code, caption, weightedQ from item_choices where item_id='B10'
----------------------------------------------
| item_id | code | caption | weightedQ |
----------------------------------------------
| B10 | BK | Black | 57.5 |
| B10 | BL | Blue | 26 |
| B10 | IV | Ivory | 153.5 |
| B10 | TL | Teal | 103.5 |
| B10 | TN | Tan | 131.5 |
| B10 | L | Large | 0 |
| B10 | M | Medium | 0 |
| B10 | S | Small | 0 |
| B10 | XL | X-Large | 0 |
| B10 | XXL | XX-Large | 0 |
----------------------------------------------
Number of rows returned: 10
And then the query:
select code, caption, weightedQ from item_choices where item_id='B10' having weightedQ= max(weightedQ)
*** No rows returned ***
Looking through the MySQL docs on Group By and Having I noticed that they talk a lot about having both in a query, so I did not know if that was a requirement and tried this:
select item_id, code, caption, weightedQ from item_choices where item_id='B10'
group by weightedQ having weightedQ = max(weightedQ)
------------------------------------------
| item_id | code | caption | weightedQ |
------------------------------------------
| B10 | L | Large | 0 |
| B10 | BL | Blue | 26 |
| B10 | BK | Black | 57.5 |
| B10 | TL | Teal | 103.5 |
| B10 | TN | Tan | 131.5 |
| B10 | IV | Ivory | 153.5 |
------------------------------------------
Number of rows returned: 6
... which is interesting, but of course not what I am looking for unless I do the following:
select item_id, code, caption, weightedQ from item_choices where item_id='B10'
group by weightedQ having weightedQ = max(weightedQ) order by weightedQ DESC limit 1
------------------------------------------
| item_id | code | caption | weightedQ |
------------------------------------------
| B10 | IV | Ivory | 153.5 |
------------------------------------------
Number of rows returned: 1
... which looks WAY overkill, and in fact should be more simple like:
select item_id, code, caption, weightedQ from item_choices where item_id='B10' order by weightedQ DESC limit 1
------------------------------------------
| item_id | code | caption | weightedQ |
------------------------------------------
| B10 | IV | Ivory | 153.5 |
------------------------------------------
Number of rows returned: 1
... voila, I have my answer. But what am I missing in the HAVING clause? It looks so promising...