title: Inner join on more than 2 tables
body: <p>I have 3 different tables <code>balance</code>,<code>received</code>,<code>expenses</code> with following data in it.
  <strong>Table received:</strong></p>
  
  <pre><code>mysql&gt; select * from received;
  +-----+---------+-----------------+---------------------+
  | rid | site_id | received_amount | receive_date        |
  +-----+---------+-----------------+---------------------+
  |   1 |       1 |             500 | 2015-08-19 18:16:51 |
  |   2 |       1 |             600 | 2015-08-19 18:16:52 |                                                                                                                                       
  |   3 |       1 |             500 | 2015-08-20 18:16:52 |                                                                                                                                       
  |   4 |       1 |             500 | 2015-08-19 18:16:52 |
  +-----+---------+-----------------+---------------------+
  </code></pre>
  
  <p><strong>Table expenses:</strong></p>
  
  <pre><code>mysql&gt; select * from expenses;
  +-----+---------+----------------+---------------------+
  | eid | site_id | expense_amount | expense_date        |
  +-----+---------+----------------+---------------------+
  |   1 |       1 |            500 | 2015-08-19 18:17:11 |
  +-----+---------+----------------+---------------------+
  </code></pre>
  
  <p><strong>Table balance:</strong></p>
  
  <pre><code>mysql&gt; select * from balance;
  +----------------+---------+---------------+--------------+-----------------+-----------------+------+------+---------------------+
  | transaction_id | site_id | account_title | particulars  | opening_balance | closing_balance | rid  | eid  | transaction_date    |
  +----------------+---------+---------------+--------------+-----------------+-----------------+------+------+---------------------+
  |              1 |       1 | test1         | test1 values |               0 |             500 |    1 | NULL | 2015-08-19 18:16:51 |
  |              2 |       1 | test1         | test1 values |             500 |            1100 |    2 | NULL | 2015-08-19 18:16:52 |
  |              3 |       1 | test1         | test1 values |            1100 |            1600 |    3 | NULL | 2015-08-20 18:16:52 |
  |              4 |       1 | test1         | test1 values |            1100 |            1600 |    4 | NULL | 2015-08-19 18:16:52 |
  |              5 |       1 | test1         | test1 values |            1600 |            1100 | NULL |    1 | 2015-08-19 18:17:11 |
  +----------------+---------+---------------+--------------+-----------------+-----------------+------+------+---------------------+
  </code></pre>
  
  <p>I am trying to merge the amount of received and expenses into balance table using following query but somehow I am not able to get correct way to get it.</p>
  
  <pre><code>select 
        b.transaction_id,
        b.site_id,
        b.account_title,
        b.particulars,
        b.opening_balance,
        r.received_amount,
        e.expense_amount,
        b.closing_balance,
        b.transaction_date 
     from 
        balance b 
           inner join received r 
              on b.site_id = r.site_id 
           inner join expenses e 
              on b.site_id = e.site_id 
     group by 
        b.transaction_id;
  </code></pre>
  
  <p>I am trying to get this output</p>
  
  <pre><code>+----------------+---------+---------------+--------------+-----------------+-----------------+----------------+-----------------+---------------------+
  | transaction_id | site_id | account_title | particulars  | opening_balance | received_amount | expense_amount | closing_balance | transaction_date    |
  +----------------+---------+---------------+--------------+-----------------+-----------------+----------------+-----------------+---------------------+
  |              1 |       1 | test1         | test1 values |               0 |             500 |            NULL |             500 | 2015-08-19 18:16:51 |
  |              2 |       1 | test1         | test1 values |             500 |             600 |            NULL |            1100 | 2015-08-19 18:16:52 |
  |              3 |       1 | test1         | test1 values |            1100 |             500 |            NULL |            1600 | 2015-08-20 18:16:52 |
  |              4 |       1 | test1         | test1 values |            1600 |             NULL |            500 |            1100 | 2015-08-19 18:16:52 |
  |              5 |       1 | test1         | test1 values |            1100 |             500 |            NULL |            1600 | 2015-08-19 18:17:11 |
  +----------------+---------+---------------+--------------+-----------------+-----------------+----------------+-----------------+---------------------+
  </code></pre>