title: Join two tables with condition
body: <p>I have to tables and I would like to join them with a SQL-Query. It might be the easiest thing of the world but... well.</p>
  
  <p>Table "count":</p>
  
  <pre><code>-----------------------------
  ¦ id   ¦ segment    ¦ count ¦
  """""""""""""""""""""""""""""
  ¦ 1    ¦ fruits     ¦ 0     ¦
  -----------------------------
  ¦ 2    ¦ sweets     ¦ 2     ¦
  -----------------------------
  </code></pre>
  
  <p>Table "food":</p>
  
  <pre><code>-------------------------------------
  ¦ id   ¦ type            ¦ segment  ¦ 
  """""""""""""""""""""""""""""""""""""
  ¦ 1    ¦ banana          ¦ fruits   ¦
  -------------------------------------
  ¦ 2    ¦ cranberries     ¦ fruits   ¦
  -------------------------------------
  ¦ 3    ¦ strawberries    ¦ fruits   ¦
  -------------------------------------
  ¦ 4    ¦ chocolate       ¦ sweets   ¦
  -------------------------------------
  ¦ 5    ¦ candy           ¦ sweets   ¦
  -------------------------------------
  </code></pre>
  
  <p>I would like to fill a "foodbox" with fruits and sweets. Only sweets can still be added to the "foodbox" as there are already enough fruits in it.</p>
  
  <p>How can I list just sweets (chocolate and candy) because fruits cannot be added anymore (fruits = 0)?</p>
  
  <p>My query so far:</p>
  
  <pre><code>SELECT type.food
  FROM count, food 
  WHERE type.food LIKE '%$query%' AND segment.food &gt; '1'
  </code></pre>
  
  <p>(The items should be listed after the user typed in the desired item in a searchfield. Therefore I used LIKE.)</p>
  
  <p>Any help is much appreciated!</p>