Home » SQL & PL/SQL » SQL & PL/SQL » Union All
Union All [message #355105] Wed, 22 October 2008 12:41 Go to next message
ada26
Messages: 15
Registered: September 2007
Location: cleveland
Junior Member
I have a query below, EMP1 is current records, EMP2 is historical. In cases that EMPLOYEE ABC is present on both tables, this query would give me 2 records; how can I get only 1 output.. or SUM the hrs credit.

SELECT EMP_NAME, SUM(HRS_CREDIT)
FROM EMP1
UNION
SELECT EMP_NAME, SUM(HRS_CREDIT)
FROM EMP2;

-------------
BOB SMITH 12
BOB SMITH 0
JANE DOE 24
JANE DOE 3

-------------

OUTPUT SHOULD BE;

BOB SMIT 12
JANE DOE 27






Re: Union All [message #355106 is a reply to message #355105] Wed, 22 October 2008 12:47 Go to previous messageGo to next message
Michel Cadot
Messages: 68737
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
This has already been said to you.
Read and follow OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code (See SQL Formatter) and align the columns in result.
Use the "Preview Message" button to verify.
Also always post your Oracle version (4 decimals).

Regards
Michel
Re: Union All [message #355116 is a reply to message #355105] Wed, 22 October 2008 13:57 Go to previous message
joicejohn
Messages: 327
Registered: March 2008
Location: India
Senior Member
@ada26,

I think you might be interested in INLINE Views.

Follow the link to get help on SUM Function(if you need)

Hope these helps.

Regards,
Jo
Previous Topic: problem in ordering query
Next Topic: ORA-02046: distributed transaction already begun
Goto Forum:
  


Current Time: Wed Feb 19 03:25:12 CST 2025