sqlinformix

update Informix table with joins


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.key = c.key
a.code = 10
b.tor = 'THE'
a.group = 4183
a.no in ('1111','1331','1345')

I get the generic -201 'A syntax error has occurred' message, but I can't see what's wrong.


Solution

  • The following answer is only valid for Informix versions before 11.10, in later versions it will raise a syntax error. For 11.10 and later versions, see this answer.

    Your syntax error is table1.code:

    SET table1.code = 100
    

    You need to reference the table by the assigned alias. In this case, change it to:

    SET a.code = 100
    

    Full code

    UPDATE table1
    SET a.code = 100
    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')