Union All, Distinct and SUM.....same query....
755165Aug 16 2010 — edited Aug 16 2010Hi guys, I am using Oracle 10g.
I have two tables,
table A (A number, B varchar, C date, D number)
table B (E number, F varchar, G date, H number)
now I want to do a Union of these two tables, keep the distinct of the union and at the end, when A and E are equal they should SUM(D + H).
I already tried to make the query, that could stay something like this:
select distinct
(select A, B, C from TABLE A
union all
select E, F, G from TABLE B),
amount as (sum (D + H) where A=E)
from
TABLE A,
TABLE B
But first, I am a noob, second I believe that this logic is correct (but at the end it does nothing).
Can anyone help?
Thanks a lot,
Pipoca
Edited by: Pipoca on 16-Aug-2010 05:48