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 -> update joined columns

update joined columns

From: Jan van Veldhuizen <janvv_at_xs4all.nl>
Date: Tue, 18 Jan 2005 00:20:50 +0100
Message-ID: <41ec4801$0$6210$e4fe514c@news.xs4all.nl>


I have an update that updates two columns in a join.:

update table1
  set col1 = (select avg(colx)
    from table2
    where table2.id = table1.id
    group by table2.id),
  set col2 = (select avg(coly)
    from table2
    where table2.id = table1.id
    group by table2.id)

This looks inefficient because the select on table2 is done twice.

Can this be done smarter?

Nota bene: the sql statement must be compatible with both SqlServer and Oracle. Received on Mon Jan 17 2005 - 17:20:50 CST

Original text of this message

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