Subject Re: [firebird-support] How to mimic an UPDATE with a JOIN
Author Lucas Franzen
Robert,


robert_difalco schrieb:
> I would like to do something like this:
>
> UPDATE Versions SET
> Versions.DATA=-1,
> Versions.ATTRIBS=-1
> FROM Versions JOIN Elems ON Versions.ELEM_ID=Elems.ID
> WHERE (Versions.ID <> Elems.GOLDEN_ID
> AND (Versions.NUM <= (Elems.LAST_VER_NUM - 3))));
>
> Unfortunately, at least in 1.0.3 I don't think I can do JOINS in an
> UPDATE statment.

I don't think you can do this in neither in FB5.x nor SQL-22 ;-)

Given I got your sql right try sth. like:

UPDATE Versions SET
Versions.DATA=-1,
Versions.ATTRIBS=-1

WHERE EXISTS
( SELECT * FROM Elems
WHERE Versions.ELEM_ID=Elems.ID AND
Versions.ID <> Elems.GOLDEN_ID AND
Versions.NUM <= Elems.LAST_VER_NUM - 3
);


Luc.