Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Updating correlated subqueries

Updating correlated subqueries

From: dean <deanbrown3d_at_yahoo.com>
Date: 26 Jan 2007 10:57:29 -0800
Message-ID: <1169837849.062961.112240@a75g2000cwd.googlegroups.com>


create table T (F1 number, F2 number);
create table U (F1 number, F2 number);

insert into T values (1,1);
insert into T values (2,2);
insert into T values (3,3);
insert into T values (4,4);

insert into U values (1,111);
insert into U values (2,222);

commit;

select * from T;

       F1 F2
---------- ----------

         1          1
         2          2
         3          3
         4          4

4 rows selected.

--UPDATE QUERY
update T
set F2 =
(
  select F2
  from U
  where U.F1 = T.F1
)
where T.F1 in (select F1 from U);

2 rows updated.

select * from T;

        F1 F2
---------- ----------

         1        111
         2        222
         3          3
         4          4

4 rows selected.

Ok, given the above simplified update on a correlated query, is there any other way that might be more efficient that using the IN clause for the WHERE statement? Basically I only want to update the values where there is a match.

Thanks!

Dean
Oracle 9.2, 10.1, Windows. Received on Fri Jan 26 2007 - 12:57:29 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US