Subject | Re: [firebird-support] Re: 4 most recent detail rows per master row |
---|---|
Author | Milan Babuskov |
Post date | 2007-09-23T18:33:29Z |
Leyne, Sean wrote:
than 4 and 3 is also less than four, so it would return all (0,1,2,3) rows.
Anyway, as you wrote - a nice execute statement would be a much better
solution.
--
Milan Babuskov
http://www.guacosoft.com
>>Assuming that detail and master and joined on field called "id":Actually, I did get it. Zero is less than 4, 1 is less than 4, 2 is less
>>
>>select d.*
>>from detail d
>>join master m on d.id = m.id
>>where 4 > (
>> select count(*)
>> from detail d2
>> where d2.id = m.id
>> and d2.date < d.date)
>
>
> Milan got it close but not quite (it wouldn't return anything for Master
> which had less than 4 details)
than 4 and 3 is also less than four, so it would return all (0,1,2,3) rows.
Anyway, as you wrote - a nice execute statement would be a much better
solution.
--
Milan Babuskov
http://www.guacosoft.com