I want to do a count on a certain value in a column. Structure looks like this;
FieldName       FieldValue
food            fruit
food            fruit
food            fruit
food            vegetable
MySQL query looks like this:
SELECT `FieldValue` AS `type`,
COUNT(case when `FieldValue` = 'fruit' then 1 end)AS `counts`
FROM `mytable`
WHERE `FieldName` LIKE '%food%' 
GROUP BY `FieldName`
And it returns this what is OK:
type        counts
fruit       3
But when i change "fruit" into "vegetable" :
SELECT `FieldValue` AS `type`,
COUNT(case when `FieldValue` = 'vegetable' then 1 end)AS `counts`
FROM `mytable`
WHERE `FieldName` LIKE '%food%' 
GROUP BY `FieldName`
I get this back:
type        counts
fruit       1
The count is OK but the type is wrong it should be 'vegetable'. What am i doing wrong here? Maybe the solution is very simple but i just dont see it.
 
     
    