Home » SQL & PL/SQL » SQL & PL/SQL » Merge columns
Merge columns [message #285281] Tue, 04 December 2007 03:34 Go to next message
Hunter_wow
Messages: 31
Registered: November 2007
Member
Hello. I would like to know how to merge(or what to call it) columns in oracle. Example:

Table 1:
Employe | Project

Table 2:
Project | Sallary

Every employe will have made a number of projects. How can I get a table with the total sallary for every employe? I cant think of any way to solve it. Any tips?

[Updated on: Tue, 04 December 2007 03:34]

Report message to a moderator

Re: Merge columns [message #285282 is a reply to message #285281] Tue, 04 December 2007 03:36 Go to previous messageGo to next message
rajavu1
Messages: 1574
Registered: May 2005
Location: Bangalore , India
Senior Member

It is called 'Join' not 'Merge'

What did u try so far ?

Thumbs Up
Rajuvan.
Re: Merge columns [message #285283 is a reply to message #285281] Tue, 04 December 2007 03:36 Go to previous messageGo to next message
Littlefoot
Messages: 21823
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
I'd join those tables and use SUM function to compute total salary. Check the OraFAQ Forum Guide; in there you'll find useful links to Oracle documentation.
Re: Merge columns [message #285284 is a reply to message #285281] Tue, 04 December 2007 03:36 Go to previous messageGo to next message
Michel Cadot
Messages: 68737
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
JOINS
SUM
GROUP BY

Regards
Michel
Re: Merge columns [message #285288 is a reply to message #285281] Tue, 04 December 2007 03:40 Go to previous messageGo to next message
rajavu1
Messages: 1574
Registered: May 2005
Location: Bangalore , India
Senior Member

@Hunter_wow :

You are too lucky to get 3 answers at time that too within 2 minutes of posting Smile

Thumbs Up
Rajuvan

[Updated on: Tue, 04 December 2007 03:40]

Report message to a moderator

Re: Merge columns [message #285299 is a reply to message #285281] Tue, 04 December 2007 03:51 Go to previous messageGo to next message
Hunter_wow
Messages: 31
Registered: November 2007
Member
Yea, thanks a lot! Guess it´s my lucky day =P. I belive I manage to put together all employs and their points but still dont understand how I should Sum it together:

SELECT a.sallary, b.employe FROM table1 a, table2 b WHERE a.project = b.project;


Example view for the result:
Sallary | Employe
5000 rajavu1
10000 Michel
1000 rajavu1

Need to make some kind of Join and Sum in the same time for this?

[Updated on: Tue, 04 December 2007 03:54]

Report message to a moderator

Re: Merge columns [message #285304 is a reply to message #285299] Tue, 04 December 2007 03:56 Go to previous messageGo to next message
Michel Cadot
Messages: 68737
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Read the links I posted and work on it.

Regards
Michel
Re: Merge columns [message #285315 is a reply to message #285281] Tue, 04 December 2007 04:03 Go to previous messageGo to next message
rajavu1
Messages: 1574
Registered: May 2005
Location: Bangalore , India
Senior Member


Quote:

Need to make some kind of Join and Sum in the same time for this?

Hmhm...

You are approaching your desired result. what is missing is Group by and sum() . Just one more step behind your result. Smile. Try using michel's link. One more link

Thumbs Up
Rajuvan.

[Updated on: Tue, 04 December 2007 04:04]

Report message to a moderator

Re: Merge columns [message #285317 is a reply to message #285281] Tue, 04 December 2007 04:13 Go to previous messageGo to next message
Hunter_wow
Messages: 31
Registered: November 2007
Member
Tons of thanks. Really nice link rajavu1!!
This gave me the result I wanted:
SELECT Employe, SUM(Sallary) as "Sallary"
FROM table
GROUP BY Employe;

Very Happy
Re: Merge columns [message #285331 is a reply to message #285317] Tue, 04 December 2007 04:43 Go to previous messageGo to next message
Littlefoot
Messages: 21823
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Really? In that case

  • you fooled us when posting 'table1' and 'table2' in your first post (as 'employee' and 'salary' do not belong to the same table),
  • you didn't find the solution yet,
  • you didn't post the actual query which gave you the solution.
Re: Merge columns [message #285368 is a reply to message #285281] Tue, 04 December 2007 05:36 Go to previous messageGo to next message
Hunter_wow
Messages: 31
Registered: November 2007
Member
In my second post I said I managed to put together table1 and table2 to one table Wink
Re: Merge columns [message #285375 is a reply to message #285281] Tue, 04 December 2007 05:45 Go to previous messageGo to next message
kir_ait
Messages: 198
Registered: November 2007
Location: Bangalore,India
Senior Member

Quote:

This gave me the result I wanted:

SELECT Employe, SUM(Sallary) as "Sallary"
FROM table
GROUP BY Employe;



Then this is not your actual desired output anyway!
I hardly can find joining table1 and table2 in the above query. It is there in your second post, but not here. Wink

Kiran,

[Updated on: Tue, 04 December 2007 05:47]

Report message to a moderator

Re: Merge columns [message #285444 is a reply to message #285368] Tue, 04 December 2007 11:05 Go to previous message
flyboy
Messages: 1903
Registered: November 2006
Senior Member
Quote:

Table 1: Employe | Project
Table 2: Project | Sallary
Every employe will have made a number of projects.
So, if I understand the data model, there is N:1 relationship between Table1 and Table2.
Quote:

I managed to put together table1 and table2 to one table
If my assumption is correct, you just broke the second normal form. Not a good idea at all.
Prepare for many difficulties, especially the possibility of having different Sallary values for one Project.
Previous Topic: Help with cleanup query
Next Topic: database and charectorstics
Goto Forum:
  


Current Time: Mon Feb 17 21:59:39 CST 2025