Skip to content Skip to sidebar Skip to footer

Update One Table From Another Without Join Statement

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 dur

Solution 1:

Instead of trying to use UPDATE, use MERGE:

mergeinto 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 thenupdateset 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.

Solution 2:

Update your query as follows

update elements E set E.END_I = (selectfirst1 n.node_num from nodes N 
where (N.XI =E.X_I and N.YI = E.Y_I and N.ZI=E.Z_I) )
whereexists (select1from 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 doesn't know that subquery returns only one row.

Post a Comment for "Update One Table From Another Without Join Statement"