Subject Re: [ib-support] re: "token unknown 'order' "
Author Nando Dessena

> I have records like this
> qty numeric (15,2)
> d_mov date
> I want to take the most recent date present in the table (say T) and sum
> fields qty for all the records that have d_mov=T.

I think your statement has two problems:

a) FIRST is not guaranteed to return a singleton select (hence you can't
use it in a subquery), and
b) FIRST needs an ORDER BY clause to be of any use, something that the
SQL standard forbids in a subquery, as I recall. You basically have two

select sum(a.qty) from mv_li a
where a.d_mov = (select max(b.d_mov) from mv_li b)

The second one is to write a stored procedure to do the job, but if the
tables are correctly indexed the former should be fast enough.

BTW, do you really understand at a glance what a table called "mv_li"
contains? Just curious ;-)