Subject | RE: [firebird-support] Re: 4 most recent detail rows per master row |
---|---|
Author | Sasha Matijasic |
Post date | 2007-09-21T21:25:41Z |
> Milan got it close but not quite (it wouldn't return anythingActually, Milan's query is fine.
> for Master
> which had less than 4 details)
>
> Try this:But your's is not because it returns more than 4 detail rows if they exist
>
> 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
> )
>
... it should be
... where d.date in (select first 4 d2.date...)
And I think column can not be named date...
Sasha