Subject RE: [firebird-support] Re: 4 most recent detail rows per master row
Author Sasha Matijasic
> Milan got it close but not quite (it wouldn't return anything
> for Master
> which had less than 4 details)
>
Actually, Milan's query is fine.

> Try this:
>
> select
> d.*
> from
> detail d
> join master m on d.id = m.id
> where
> d.id in(
> select
> first 4
> d2.id
> from detail d2
> where d2.id = m.id
> ORDER by d2.date desc
> )
>
But your's is not because it returns more than 4 detail rows if they exist
... it should be

... where d.date in (select first 4 d2.date...)

And I think column can not be named date...

Sasha