title: Noob needs advise on three tables in postgresql DB
body: <p>I've very minor experience at working with databases( I only know the absolute basics). With that stated I guess my problem is rather easy to solve for more experienced minds.  </p>
  
  <p>My question is:</p>
  
  <p>I need a way to be able to search for example "all types of Aluminium and all its sub_materials"?</p>
  
  <p>I can do simple queries like </p>
  
  <pre><code>SELECT * 
  FROM sub_materials 
  WHERE category_id = 2;
  </code></pre>
  
  <p>So what I'm asking for is basically to be able to see the whole branch of Aluminium. I've looked at <code>ltree</code>and <code>Closure Tables</code> But I'm to much of a Noob to figure it out by my self.</p>
  
  <p>I believe I have to connect the tables somehow as "grandparent, parent, child" or something similar, but I've no idea if there is some other way or?</p>
  
  <p>I'm not even sure if I'm doing this the right way.
  Can someone advise me on this?</p>
  
  <p>I've three tables in a database.(below are samples from the tables)</p>
  
  <ol>
  <li><p><code>materials_category</code> Holds all the categories for every material in the DB.</p></li>
  <li><p><code>materials</code> Holds the Category name and id, material_names and ids and the values for each material.</p></li>
  </ol>
  
  <p>Some materials has sub_categories. not all but some.
  3. <code>sub_materials</code> Holds the category info, material name and id, the sub_material name and id and the sub_material values.</p>
  
  <pre><code>1. `materials_category`
  
   |category_id| category_name|
  ------------------------------
   |    1      | Aggregate    |
   |    2      | Aluminium    |
   |    3      | Asphalt      |
  
  
  2. `materials`
      |category_id |category_name |material_id |material_name|EE_1|EE_2|EC_1|EC_2
      ---------------------------------------------------------------------------
      | 1          |Aggregate     | 1          | General     |3   |0   | 52 | 8
      | 2          |Aluminium     | 2          | General     |55  |7   |  9 | 24
      | 2          |Aluminium     | 3          | Cast Pr     |34  |30  | 22 | 28
      | 2          |Aluminium     | 4          | Extrud.     |65  |16  |  8 | 74
      | 2          |Aluminium     | 5          | Rolled      |15  | 0  |  9 | 61
      | 3          |Asphalt       | 6          |Asphalt, 4%  |2   |22  | 6  | 54
      | 3          |Asphalt       | 7          |Asphalt, 5%  |3   |91  |  1 | 4
  
  3. `sub_materials`
  
  |category_id|category_name|material_id|material_name|sub_mar_id|sub_mar_name|EE_1|EE_2|EC_1|EC_2|   
  |2          |Aluminium    |2          |General      |1         |Virgin      |21  |5   |9   |60  |   
  |2          |Aluminium    |2          |General      |2         |Recycled    |29  |3   |8   |9   |
  </code></pre>