Home » SQL & PL/SQL » SQL & PL/SQL » update one table with the values from second table
update one table with the values from second table [message #185390] Tue, 01 August 2006 08:52 Go to next message
Mahesh P
Messages: 69
Registered: September 2004

I amhaving 2 tables as shown below.

create table tab1(id number(5),name varchar2(30));
create table tab2(id number(5),name varchar2(30));

insert into tab1 values(1,'A');
insert into tab1 values(2,'B');
insert into tab1 values(3,'C');
insert into tab1 values(4,'D');

insert into tab2 values(10,'A');
insert into tab2 values(20,'B');
insert into tab2 values(30,'C');
insert into tab2 values(40,'D');

Now i want to update the table tab1's 'id' column with the values from the id column of tab2
i.e the result of table tab1 after update will look something like below:

Note: the name column value in both the tables were same.


How can i achive this?

please help me.

thanks & regards,
Mahesh p
Re: update one table with the values from second table [message #185393 is a reply to message #185390] Tue, 01 August 2006 09:01 Go to previous message
Messages: 189
Registered: May 2006
Location: NJ,USA
Senior Member

update tab1  set tab1.id = ( select tab2.id 
                               from tab2 
                              where tab2.name = tab1.name)
where exists (select 'X' 
                from tab2 
               where tab2.name = tab1.name )

Previous Topic: Columns to Rows and De Duping
Next Topic: Monitoring all indexes through execute immediate
Goto Forum:

Current Time: Wed Oct 26 04:45:06 CDT 2016

Total time taken to generate the page: 0.09042 seconds