Subject Re: Select question
Author Svein Erling Tysvær
Adding CLAIMSTS to my last answer makes the query

Select *
From CLAIMSPAIDREVERSED T1
Where not exists
(Select *
From CLAIMSPAIDREVERSED T2
Where T2.RXCLAIMNBR=T1.RXCLAIMNBR
And (T2.CLMSEQNBR>T1.CLMSEQNBR
or (T2.CLMSEQNBR=T1.CLMSEQNBR
and T2.CLAIMSTS<T1.CLAIMSTS)))

Set

--- In firebird-support@yahoogroups.com, "Rick DeBay" wrote:
> Thanks Alexander. One last question. I've expanded the select to
using
> three columns, and now this is what it looks like. I'm sure it's
> obvious that I'm not a DBA.
>
> Select *
> From CLAIMSPAIDREVERSED T1
> Where T1.CLMSEQNBR=
> (Select First 1 T2.CLMSEQNBR
> From CLAIMSPAIDREVERSED T2
> Where T2.RXCLAIMNBR=T1.RXCLAIMNBR
> Order By T2.CLMSEQNBR DESC)
> AND
> T1.CLAIMSTS=
> (Select First 1 T3.CLAIMSTS
> From CLAIMSPAIDREVERSED T3
> Where T3.RXCLAIMNBR=T1.RXCLAIMNBR AND T3.CLMSEQNBR=T1.CLMSEQNBR
> Order By T3.CLAIMSTS)
>
> PLAN SORT ((T2 INDEX (CLAIMNUMBER)))
> PLAN SORT ((T3 INDEX (CLAIMNUMBER)))
> PLAN (T1 NATURAL)
>
> What I'm trying to do is get the last item in a sequence, where
column 1
> counts up, column 2 down, and column 3 up. So a unique key would
> combine all three columns:
>
> 001 999 P
> 001 999 X
> 001 998 P
>
> What I created from Alexander's answer works, but it could probably
> be better.