我的一个update from的sql语句报错,语法结构问题
update db1 set status=c.status
from
(select a.id as a_id,a.status from db2 a,db3 b where a.id=b.a_id)
c
where c.a_id=a_idorcal不支持这种from的写法?类似写法在sql-server好像可以的吧?

解决方案 »

  1.   

    update db1 a
    set status=
    (
    select 
    from
    (select a.id as a_id,a.status from db2 a,db3 b where a.id=b.a_id) c
    where a.a_id=c.a_id)
    where c.a_id in (select a.id as a_id from db2 a,db3 b where a.id=b.a_id)
      

  2.   

    merge into db_1
    using
    ( select db_2.id as id,db_2.status as status from db_2 inner join db_3 on db_2.id=db_3.id) c
    on(c.id=db_1.id)
    when matched then
    update set status=c.status