title: SQL Query to select products from all categories of One Parent
body: <p>I have a Product Table with this structure</p>
  
  <pre><code> id, title, slug, details, category(FK category.ID)
  </code></pre>
  
  <p>And a Category Table:
      id, name, slug, parent</p>
  
  <p>Categories have only 1 level
  If there is no parent then parent field is 0 else id of parent category saved</p>
  
  <p>Suppose I have categories structure like this:</p>
  
  <pre><code>FRUITS
  |---- APPLE
  |---- MANGO
  |---- BANANA
  </code></pre>
  
  <p>I use a Category slug to query products from a category</p>
  
  <p>category.php?cat=apple
  category.php?cat=mango</p>
  
  <p>1st query:</p>
  
  <pre><code>select id,name from category WHERE slug='$catslug'
  </code></pre>
  
  <p>After getting ID of category then use query to get results of that ID from products table</p>
  
  <pre><code>select * from products where category=$categoryid
  </code></pre>
  
  <p>What query is required if I want to fetch all products posted in FRUITS?</p>
  
  <pre><code>category.php?cat=fruits
  </code></pre>
  
  <p>I want to get all products posted in apple, mango, banana (all children of fruits)</p>
  
  <p>Only the child IDs are saved in product table how do I link parent category apple with these?</p>