Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Union All, Distinct and SUM.....same query....

755165Aug 16 2010 — edited Aug 16 2010
Hi 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
This post has been answered by 618702 on Aug 16 2010
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 13 2010
Added on Aug 16 2010
13 comments
8,328 views