title: MySQL select child records where all parent records have the same child records, excluding all other child records
body: <p>I need help with a tricky MySQL query.</p>
  
  <p>These are the tables and data:</p>
  
  <p><b>Ingredients</b></p>
  
  <pre>
  IngredientID  | Name
  1             | Ketchup
  </pre>
  
  <p><br>
  <b>Products</b></p>
  
  <pre>
  ProductID | Name                  | IngredientID
  1         | Bills Amazing Ketchup | 1
  2         | Marys Tasty Ketchup   | 1
  </pre>
  
  <p><br>
  <b>RedFlags</b></p>
  
  <pre>ProductID | RedFlagID
  1         | 1 (Gluten)
  1         | 2 (Egg)
  2         | 1 (Gluten)
  </pre>
  
  <p><br>
  A cooking ingredient can have multiple products. For example the ingredient Ketchup can have different types of ketchup to choose from at the store.</p>
  
  <p>In this case, Ketchup has 2 possible products to choose from, ‘Bills Amazing Ketchup’ and ‘Marys Tasty Ketchup’.</p>
  
  <p>Each product will have its own dietary red flags. For example Bills Amazing Ketchup contains Gluten and Egg, whereas Marys Tasty Ketchup only contains Gluten but NO egg.</p>
  
  <p>What I want to do is, against the Ingredient show only the Red Flags that are applicable.</p>
  
  <p>For example, the two products both contain Gluten and only 1 contains Egg. So Egg is NOT a red flag for the Ketchup ingredient because a product that doesn’t contain egg exists and the customer can purchase the Egg free alternative, therefore Egg must NOT show as a red flag against the ingredient.</p>
  
  <p>However, since both products contain Gluten and there is no Gluten free alternative to choose from, therefore the ingredient must show Gluten as a red flag.</p>
  
  <p>The Ketchup Ingredient should therefore show the following related data:</p>
  
  <pre>
  IngredientID | RedFlagID 
  1            | 1 (Gluten)
  </pre>
  
  <p>This query must be fast because the database will contain a lot of products.</p>
  
  <p>So Im not keen on having counts if possible, as I believe this would slow it down.</p>
  
  <p>Thanks.</p>