title: Connecting 5 tables but excluding values from the 5th
body: <h3>Data tables</h3>
  
  <p>I got 5 tables with certain values:</p>
  
  <ol>
  <li>Table: <code>tbl_1</code></li>
  </ol>
  
  <pre><code>+-------+-------+
  | nm_id | name  |
  +-------+-------+
  |     1 | name1 |
  |     2 | name2 |
  |     3 | name3 |
  +-------+-------+
  </code></pre>
  
  <ol start="2">
  <li>Table: <code>tbl_2</code></li>
  </ol>
  
  <pre><code>+-------+-------+-------+
  |post_id| nm_id | post  |
  +-------+-------+-------+
  |     1 |     1 | text1 |
  |     2 |     1 | text2 |
  |     3 |     2 | text3 |
  +-------+-------+-------+
  </code></pre>
  
  <ol start="3">
  <li>Table: <code>tbl_3</code></li>
  </ol>
  
  <pre><code>+-------+-------+-------+-------+
  |com_id |post_id| nm_id | com   |
  +-------+-------+-------+-------+
  |     1 |     1 |     1 | text1 |
  |     2 |     2 |     1 | text2 |
  |     3 |     2 |     2 | text3 |
  +-------+-------+-------+-------+
  </code></pre>
  
  <ol start="4">
  <li>Table: <code>tbl_4</code></li>
  </ol>
  
  <pre><code>+-------+-------+-------+-------+-------+
  |com2_id|com_id||post_id| nm_id | com2  |
  +-------+-------+-------+-------+-------+
  |     1 |     1 |     1 |     1 | text1 |
  |     2 |     2 |     2 |     1 | text2 |
  |     3 |     1 |     2 |     2 | text3 |
  +-------+-------+-------+-------+-------+
  </code></pre>
  
  <ol start="5">
  <li>Table: <code>tbl_5</code></li>
  </ol>
  
  <pre><code>+-------+-------+-------+-------+-------+-------+
  |rep_id |com2_id|com_id||post_id| nm_id | text  |
  +-------+-------+-------+-------+-------+-------+
  |     1 |  null |     1 |     1 |     1 | text1 |
  |     2 |  null |  null |     1 |     1 | text2 |
  +-------+-------+-------+-------+-------+-------+
  </code></pre>
  
  <h3>What I tried</h3>
  
  <p>I need to get all the values, but the idea is to <strong>exclude values from <code>tbl_5</code></strong> from result. So far what I do is:</p>
  
  <ol>
  <li>select <code>tbl_2</code> then join <code>tbl_1</code> on <code>nm_id</code> then exclude <code>tbl_5</code> on <code>post_id</code> -> <strong>1stVariable</strong></li>
  </ol>
  
  <pre><code>SELECT tbl_2.*, name.tbl_1
  FROM tbl_2
  INNER JOIN tbl_2 ON tbl_1.nm_id = tbl_2.nm_id
  LEFT JOIN tbl_5 ON tbl_2.post_id = tbl_5.post_id
  WHERE tbl_2.post_id = *variable* AND tbl_5.rep_id IS NULL
  </code></pre>
  
  <ol start="2">
  <li>select <code>tbl_3</code> then join <code>tbl_2</code> on <code>com_id</code> then join <code>tbl_1</code> on <code>nm_id</code> exclude <code>tbl_5</code> on <code>com_id</code> -> <strong>2ndVariable</strong></li>
  </ol>
  
  <pre><code>SELECT tbl_3.*, name.tbl_1
  FROM tbl_3
  INNER JOIN tbl_3 ON tbl_1.nm_id = tbl_3.nm_id
  LEFT JOIN tbl_5 ON tbl_3.com_id = tbl_5.com_id
  WHERE tbl_3.com_id = *variable* AND tbl_5.rep_id IS NULL
  </code></pre>
  
  <ol start="3">
  <li>select <code>tbl_4</code> then join <code>tbl_1</code> on <code>nm_id</code> exclude <code>tbl_5</code> on <code>com2_id</code> -> <strong>3rdVariable</strong></li>
  </ol>
  
  <pre><code>SELECT tbl_4.*, name.tbl_1
  FROM tbl_4
  INNER JOIN tbl_4 ON tbl_1.nm_id = tbl_4.nm_id
  LEFT JOIN tbl_5 ON tbl_4.com2_id = tbl_5.com2_id
  WHERE tbl_4.com2_id = *variable* AND tbl_5.rep_id IS NULL
  </code></pre>
  
  <h3>My current output is JSON</h3>
  
  <pre><code>{
    post:{...},
    com:{...},
    com2:{...}
  }
  </code></pre>
  
  <h3>Needed JSON output</h3>
  
  <p>What happens is that my .js gets so long and complicated with 3 separated arrays. I was trying to get everything within 1st variable, what i can't understand is how to get array within array:</p>
  
  <pre><code>{
     post: {
       post_id: "post_id",
       name: "name",
       com: {
         com_id:"com_id",
         com:"com",
         name:"name",
         com2:{
           com2_id:"com2_id",
           com2:"com2",
           name:"name",
           }
        },
     }
  }
  </code></pre>
  
  <p>I really hope this is understandable. Thanks in advance.</p>