mysql error: an alias was previously found
<p>I am using these codes in mysql query</p>
<pre><code>    select c1.date,sum(SELECT IFNULL(cx.purchase-cx.sold,0))+MAX(p.openqty) as opening,c1.purchase,c1.sold,
    sum(SELECT IFNULL(cx.purchase-cx.sold,0))+MAX(p.openqty) + c1.purchase-c1.sold as closing 
from 
    (select open_qty as openqty from stock ) p
left join
(select IFNULL(a.date,b.date) as date,SELECT IFNULL(a.qty,0) as purchase,SELECT IFNULL(b.qty,0) as sold from arrival a FULL JOIN pouring b ON a.date = b.date order by 1) c1 
on c1.purchase +p.openqty&gt;0
left join
 (select IFNULL(a.date,b.date) as date,SELECT IFNULL(a.qty,0) as purchase,SELECT IFNULL(b.qty,0) as sold from arrival a FULL JOIN pouring b ON a.date = b.date order by 1) cx 
on c1.date&gt;cx.date
 group by c1.date,c1.purchase,c1.sold
</code></pre>
<p>It says:</p>
<pre><code>An alias was previously found. (near &quot;purchase&quot; at position 170)
An alias was previously found. (near &quot;c1&quot; at position 179)
An alias was previously found. (near &quot;sold&quot; at position 182)
An alias was previously found. (near &quot;closing&quot; at position 190)
</code></pre>
<p>MySQL said: Documentation</p>
<blockquote>
<h1>1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use</h1>
<p>near 'SELECT IFNULL(cx.purchase-cx.sold,0))+MAX(p.openqty)  as
opening,c1.purchase,c1.' at line 1</p>
</blockquote>
<p>Please help how to overcome?</p>