Subject | Re: [firebird-support] Subselects |
---|---|
Author | Helen Borrie |
Post date | 2004-03-16T13:23:27Z |
At 01:49 PM 16/03/2004 +0100, you wrote:
SELECT
m.VALID_FROM,
m.PRICE
FROM MATERIALCENA m
WHERE
m.MATERIALid = :IMATERIALID
AND m.VALID_FROM =
(select max(MC.VALID_FROM from materialcena mc
where mc.materialid = :imaterialid
and mc.VALID_FROM <= 'today')
INTO :VALID_FROM, :PRICE;
unpredictable results like you have observed. Fb 1.5 is much tighter on
these multi-table queries than its predecessors. To make use of the
improvement, write tight, clean SQL. Laxness with aliasing in self-referent
queries isn't clean.
/heLen
>HiIt is not a very safe query. This should be more robust:
>
>I wonder if the occasional problems with subselects are resolved in FB1.5 ??
>
>Here is the excerpt from our procedure:
>
> SELECT VALID_FROM, PRICE FROM MATERIALCENA
> WHERE MATERIALid = :IMATERIALID AND VALID_FROM =
> (select max(MC.VALID_FROM from materialcena mc where mc.materialid =
>:imaterialid and mc.VALID_FROM <= 'today')
> INTO :VALID_FROM, :PRICE;
>
>Suddenly subselect didn't return max(valid_from)
SELECT
m.VALID_FROM,
m.PRICE
FROM MATERIALCENA m
WHERE
m.MATERIALid = :IMATERIALID
AND m.VALID_FROM =
(select max(MC.VALID_FROM from materialcena mc
where mc.materialid = :imaterialid
and mc.VALID_FROM <= 'today')
INTO :VALID_FROM, :PRICE;
>After we restarted the server, the results are ok againProbably a coincidence.
>PS.: this problem should have been solved years agoIt was solved years ago. It's really up to you to write good SQL to avoid
unpredictable results like you have observed. Fb 1.5 is much tighter on
these multi-table queries than its predecessors. To make use of the
improvement, write tight, clean SQL. Laxness with aliasing in self-referent
queries isn't clean.
/heLen