update Informix table with joins

前端 未结 5 934
执笔经年
执笔经年 2021-01-17 14:35

Is this the correct syntax for an Informix update?

update table1
set table1.code = 100
from table1 a, table2 b, table3 c
where a.key = c.key
a.no = b.no
a.ke         


        
5条回答
  •  隐瞒了意图╮
    2021-01-17 15:01

    For Informix SE 7.25...

    1. UPDATE ... FROM ... syntax does not exist
    2. You also "Cannot modify table or view used in subquery" which is given when using Rockallite's answer

    Another solution would be to break it down into two queries:

    First, get the ROWIDs for the required records (filtered on multiple tables):

    SELECT a.ROWID
      FROM table1 a, table2 b, table3 c
     WHERE a.key = c.key
       AND a.no = b.no
       AND a.key = c.key
       AND a.code = 10
       AND b.tor = 'THE'
       AND a.group = 4183
       AND a.no IN ('1111','1331','1345')
    

    Put the result into a comma separated string.

    Then, update only those records for the main table where the ROWID was found in the first query:

    UPDATE table1 a
       SET a.code = 100
    WHERE a.ROWID in ([comma separated ROWIDs found above])
    

提交回复
热议问题