Code: Select all
SELECT sum( b.softdiet = 'TRUE' ) AS soft_cnt, sum( b.mediumdiet = 'TRUE' ) AS medium_cnt, sum( b.harddiet = 'TRUE' ) AS hard_cnt
FROM Recipe_Step a, Recipes b
WHERE a.Recipe_ID = b.Recipe_ID
AND 'TRUE' IN (b.softdiet, b.mediumdiet, b.harddiet)
AND (a.Ingred_ID =118 OR a.Ingred_ID =327)That is working fine except one little problem. A recipe which has both ingredients counts double. Is there a way I can work in DISTINCT into above query?
My solution for now would be adding a.Recipe_ID to the Select and Group by it. Then I would just count each entry > 0 as 1 with php. However as always I like to learn more about MYSQL