Home » SQL & PL/SQL » SQL & PL/SQL » Basic update question  () 1 Vote
Basic update question [message #220333] Tue, 20 February 2007 05:49 Go to next message
akkumar81
Messages: 144
Registered: February 2007
Location: india
Senior Member

Hi friends,

I explain detail

I have two table emp and dept, Emp table three columns(name,salary,age)
and Dept have two columns( name ,and salary).

In first table Emp have data's in all columns, and Dept(table) have data's only in name,not in salary column.Now i fill the salary column in Dept table from
Emp table Salary column wise.

Anybody help me.

Thanks,
Kiss07

[Updated on: Tue, 20 February 2007 06:07] by Moderator

Report message to a moderator

Re: Urgent Pls [message #220347 is a reply to message #220333] Tue, 20 February 2007 06:06 Go to previous messageGo to next message
Maaher
Messages: 7062
Registered: December 2001
Senior Member
1. Assuming that "name" is unique in your EMP table, here's one way of doing that:
UPDATE dept d
SET salary = ( select salary from emp e where e.name = d.name )


EDIT: note the changed title "Urgent pls" is not a good title. Read the sticky (tips and tricks) topic.

MHE

[Updated on: Tue, 20 February 2007 06:07]

Report message to a moderator

Re: Urgent Pls [message #220364 is a reply to message #220347] Tue, 20 February 2007 07:10 Go to previous messageGo to next message
gbarbisan
Messages: 67
Registered: August 2006
Location: Treviso - Italy
Member
Another way (assuming both D.NAME and E.NAME are primary keys):


UPDATE (
  SELECT E.NAME AS E_NAME, E.SALARY AS E_SALARY
         D.NAME AS D_NAME, D.SALARY AS D_SALARY
    FROM EMP E, DEPT D
   WHERE E.NAME = D.NAME)
SET D_SALARY = E_SALARY;

[Updated on: Tue, 20 February 2007 07:10]

Report message to a moderator

Re: Basic update question [message #220368 is a reply to message #220333] Tue, 20 February 2007 07:15 Go to previous messageGo to next message
vamsi kasina
Messages: 2107
Registered: October 2003
Location: Riyadh, Saudi Arabia
Senior Member
What is the relation between these two tables?
How to join? Any common / relevant column in both the tables?
Sample data?
Expected output?

By
Vamsi
Re: Basic update question [message #220375 is a reply to message #220368] Tue, 20 February 2007 07:51 Go to previous messageGo to next message
gbarbisan
Messages: 67
Registered: August 2006
Location: Treviso - Italy
Member
Did you read the OP?
Re: Basic update question [message #220379 is a reply to message #220375] Tue, 20 February 2007 08:06 Go to previous messageGo to next message
vamsi kasina
Messages: 2107
Registered: October 2003
Location: Riyadh, Saudi Arabia
Senior Member
I did.
Quote:
Now i fill the salary column in Dept table from
Emp table Salary column wise.

I didn't find any relation between "emp.name" and "dept.name".

Before posting the answer, I used to get clarified.
Edit:
I don't believe that emp and dept are just the table names (akkumar81's perspective) and they don't have any relation with the data in those.

By
Vamsi

[Updated on: Tue, 20 February 2007 08:19]

Report message to a moderator

Re: Basic update question [message #220402 is a reply to message #220379] Tue, 20 February 2007 10:01 Go to previous message
gbarbisan
Messages: 67
Registered: August 2006
Location: Treviso - Italy
Member
vamsi kasina wrote on Tue, 20 February 2007 15:06

I don't believe that emp and dept are just the table names



Yes, they are...
At least this is what Maaher and I understood.
Previous Topic: Check Departmet Code
Next Topic: BLOBS --IMPORTANT
Goto Forum:
  


Current Time: Thu Dec 08 16:35:50 CST 2016

Total time taken to generate the page: 0.09822 seconds