Subject | Re: Update statement question |
---|---|
Author | Adam |
Post date | 2006-02-24T02:48:07Z |
--- In firebird-support@yahoogroups.com, "Marcin Bury" <mbury@...>
wrote:
I am struggling on a Fridday afternoon to follow your table
definitions, but here goes. You should rather store reel.ID as a
foreign key in logit_scr, good normalisation techniques make these
queries a lot easier. If this works but is slow, then there are two
things to try. You can convert the sub select to a for select
statement and then do a simple update from inside, or convert it to a
where exists query (although I think in this case the optimiser will
do that anyway).
UPDATE LOGIT_SCR_ITEM SCR
SET SCR.STATUS = 1
WHERE SCR.ID in
(
select scr2.ID
from logit_wlo wlo
join logit_order orde on (wlo.ID = orde.logit_wlo_id)
join logit_reel reel on (orde.ID = reel.logit_order_id)
join logit_scr_item scr2 on (scr2.reel_code = reel.reel_code and
scr2.srv = reel.srv)
where wlo.ID = NEW.ID
);
Adam
wrote:
>LOGIT_WLO ...)
> Hello all
>
> I have four tables:
> LOGIT_WLO (id integer, logit_status integer ...)
> LOGIT_ORDER (id integer, logit_wlo_id integer -> references
> LOGIT_REEL (id integer, reel_code integer, srv char(3),logit_order_id ->
> references LOGIT_ORDER ...)reference
> LOGIT_SCR_ITEM (id, reel_code integer, srv char(3) [both fields
> LOGIT_REEL], status ...)changes its value.
>
> due some computations field 'logit_status' in table LOGIT_WLO
>single update
> Is it possible to change the 'status' field in LOGIT_SCR_ITEM in
> statement called from after_update trigger of LOGIT_WLO table like :references
>
> UPDATE LOGIT_SCR_ITEM SCR
> SET SCR.STATUS = 1
> WHERE ??????
>
> it would be simple when only one field from LOGIT_SCR_ITEM table
> LOGIT_REEL table, but what is the condition when there are morethan one field
> like in the example above.Marcin,
>
> TIA
> Marcin
>
I am struggling on a Fridday afternoon to follow your table
definitions, but here goes. You should rather store reel.ID as a
foreign key in logit_scr, good normalisation techniques make these
queries a lot easier. If this works but is slow, then there are two
things to try. You can convert the sub select to a for select
statement and then do a simple update from inside, or convert it to a
where exists query (although I think in this case the optimiser will
do that anyway).
UPDATE LOGIT_SCR_ITEM SCR
SET SCR.STATUS = 1
WHERE SCR.ID in
(
select scr2.ID
from logit_wlo wlo
join logit_order orde on (wlo.ID = orde.logit_wlo_id)
join logit_reel reel on (orde.ID = reel.logit_order_id)
join logit_scr_item scr2 on (scr2.reel_code = reel.reel_code and
scr2.srv = reel.srv)
where wlo.ID = NEW.ID
);
Adam