MySql: Sum of two columns from two different tables
<p>It might be a <strong>Repeated Question</strong>, but my problem is not solving.</p>

<p>I am trying to determine the Inward and Outward of Item using Date
<br>tables.<br></p>

<p><li>In table 1, We will call it <code>A</code> for short. I would have three columns
   namely <code>A_Dt</code>, <code>A_Na</code>, <code>A_Qty</code><br> </li>  <li> In table 2, We will call it 'B' for short. I would have three columns namely <code>B_Dt</code>, <code>B_N</code>a,<code>B_Qty</code><br>  </li>
<li>  In table 3, We will call it 'C' for short. I would
   have three columns    namely <code>C_Dt</code>, <code>C_N</code>a, <code>C_Qty</code><br>
</li><br>
Table A and B are inward and  C are outward.
<br>
I had used the revised query but adding the Third column.</p>

<p>Table Example:<br></p>

<pre><code>Table :A

    A_Dt         A_Na  A_Qty
    2016-08-01    XY     50
    2016-08-02    XY     100
    2016-08-05    XY     150
</code></pre>

<p>Table B:</p>

<pre><code>B_Dt       B_Na  B_Qty
2016-08-01  XY  150
2016-08-03  XY  100
2016-08-04  XY  200
</code></pre>

<p>Table C:</p>

<pre><code>C_Dt       C_Na  C_Qty
2016-08-01  XY  150
2016-08-03  XY  100
2016-08-04  XY  200
</code></pre>

<p>Expected Output</p>

<pre><code>Date           Inward   Outward
2016-08-01      200      150
2016-08-02      100      0
2016-08-03      100      100
2016-08-04      200      200
2016-08-05      150      0
</code></pre>

<p>Well, in this case I should use left join or following query must be worked.</p>

<p>Query:</p>

<pre><code>select t.Dt as Date, sum(t.Qty) as Inward,sum(t.outward) as outward1 from(
    select A_Dt as Dt, A_Na as Na, A_Qty as Qty from a
    union all
    select B_Dt as Dt, B_Na as Na, B_Qty as Qty from b
    union all
    select C_Dt as Dt, C_Na as Na, C_Qty as outward from c
)t
group by t.Dt, t.Na
order by t.Dt;
</code></pre>

<p>Following Error:</p>

<pre><code>#1054 - Unknown column 't.outward' in 'field list' 
</code></pre>

<p>Any thoughts would be great.Thanks in advance.</p>