Update con left join

Category: SQL and PL/SQL 9 years ago
Hola buen día.

Esta consulta en MySQL es válida

update [tabla] as t1
inner join [tabla2] as t2 on t2.id=t1.id
set t1.campo1=t2.campo1
[where]


Esa misma consulta intento recrearla en oracle, pero me generar un error, cuál sería su equivalente?


Saludos y gracias de antemano.
Like it on Facebook, +1 on Google, Tweet it or share this topic on other bookmarking websites.
  • Re: Update con left join

    by » 9 years ago


    Podría ser de esta manera.

    create table t1 (c1 int, c2 varchar2(5));
    create table t2 (c1 int, c2 varchar2(5));

    insert into t1 values (1,'A');
    insert into t1 values (2,'B');
    insert into t1 values (3,'C');
    insert into t1 values (4,'D');
    insert into t1 values (5,'E');
    insert into t2 values (1,'AA');
    insert into t2 values (2,'BB');
    insert into t2 values (3,'CC');
    insert into t2 values (4,'DD');
    insert into t2 values (5,'EE');
    commit;

    select t1.c2, t2.c2
    from t1 inner join t2 on t1.c1=t2.c1

    C2 C2
    ----- -----
    A AA
    B BB
    C CC
    D DD
    E EE


    update t2
    set t2.c2 = (select t1.c2 from t1 where t1.c1=t2.c1);
    commit;

    select t1.c2, t2.c2
    from t1 inner join t2 on t1.c1=t2.c1;

    C2 C2
    ----- -----
    A A
    B B
    C C
    D D
    E E


    Saludos

  • Re: Update con left join

    by » 9 years ago


    Gracias G3DBA

    Saludos

You do not have permissions to reply to this topic.
Powered by CjForum