php - Return true if all rows in column are true -


i've new hobby called "turn bad tasting liqueurs good" a.k.a. "mix cocktails".

since i'm nerd don't want recipes in book, read ingredients list , notice i've stuff missing. instead want have database collected recipes, , ingredients , let computer tell me recipes can 'build' ingredients have @ home. purpose i've 2 tables:

table 1: holds information many-to-many relationship

recipe | ingredient 1      | 1           1      | 2           1      | 3           2      | 1          2      | 4           

table 2: information wether ingredient available or not

ingredient | available 1          | true 2          | true 3          | true 4          | false 

all other tables aren't interesting problem.

these 2 tables can inner join-ed ingredient = ingredients.id 1 big table looks like:

recipe | ingredient | available 1      | 1          | true 1      | 2          | true 1      | 3          | true 2      | 1          | true 2      | 4          | false 

if take @ this, you'll notice can mix recipe 1, not recipe 2 since 1 ingredient missing.

what want find way result looks like:

recipe | all_available 1      | true 2      | false 

i found way check if ingredients recipe available or not:

select rti.recipe, bit_and(ingredients.available) all_available rti inner join ingredients on (ingredients.id = rti.ingredient) rti.recipe = 1 

which results:

recipe | all_available 1      | true 

but have search of specific id, want not "show me if ingredients available recipe" "show me recipes ingredients available".

is there way achieve using mysql queries?

remove where condition , instead use group rti.recipe


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -