Subject Re: UPDATE sql with join like search
Author Virgo Pärna
On Mon, 25 Feb 2013 14:29:14 +0100, Svein Erling Tysvær <svein.erling.tysvaer@...> wrote:
>
> This can be very slow, Virgo, but I guess you already know that.
>

Yes, that's why I was asking advice.:)

>
> Depends on which Firebird version you use.
>

I'm using 2.5.2.

> Try either:
>
> EXECUTE BLOCK AS
> DECLARE VARIABLE V1 INTEGER;
> BEGIN
> FOR SELECT DISTINCT VALUE1 FROM TABLE2 WHERE VALUE2 = <whatever> INTO :
> V1 DO
> BEGIN
> UPDATE TABLE1
> SET VALUE1 = NULL
> WHERE VALUE1 = :V1;
> END
> END
>

And this works just as needed. Thank you. I managed to miss this part of
Firebird features.

> If you use an old version where EXECUTE BLOCK isn't available, you could tr
> y:
>
> UPDATE TABLE1 T
> SET T.VALUE1 = NULL
> WHERE
> EXISTS(SELECT * FROM TABLE2 A WHERE VALUE2 = ? AND T.VALUE1 = A.VALUE
> 1)
>
> The last alternative will still use NATURAL, but once upon a time Firebird
> didn't transform IN into EXISTS (that's why I stopped using IN <subselect>
> last century), so it could be considerably quicker than your alternative.
>

Since I'm using 2.5.2 that's not an issue.


--
Virgo Pärna
virgo.parna@...