Update one table from another w/o join statement (firebird)

前端 未结 2 486
南笙
南笙 2021-01-28 03:19

I\'d like to update the columns in on table based on the values of another table, I use a slightly old version of Firebird 2.1 so it doesn\'t have support for the join statement

相关标签:
2条回答
  • 2021-01-28 04:05

    Update your query as follow

    update elements E set E.END_I = (select first 1 n.node_num from nodes N 
    where (N.XI =E.X_I and N.YI = E.Y_I and N.ZI=E.Z_I) )
    where exists (select 1 from nodes N where (N.XI =E.X_I and N.YI = E.Y_I and N.ZI=E.Z_I))
    

    You should add first 1 because of firebird 2.1 doestn`t know that subquery return only one row.

    0 讨论(0)
  • 2021-01-28 04:09

    Instead of trying to use UPDATE, use MERGE:

    merge into elements E
      using node N
      on N.XI = E.X_I and N.YI = E.Y_I and N.ZI = E.Z_I
      when matched then
        update set E.END_I = N.node_num
    

    Merge allows you to use another table, view or query as source of the data to update or insert into a table.

    0 讨论(0)
提交回复
热议问题