1

I have the situation where I need to get the record of the latest date and then the max SEQ number. Example:

CLIENT_ID  STATUS  DATE        SEQ
 10          1     2019-01-03   1
 10          2     2019-01-03   2
 10          4     2019-01-02   3
 10          4     2019-01-01   2

Expected result

CLIENT_ID  STATUS  DATE        SEQ
 10          2     2019-01-03   2

I have tried the following code however I am having problem to filter the SEQ variable a to get the max value

SELECT client_ID,status,maxdate 
FROM sitcli 
    INNER JOIN (SELECT MAX(date) maxdate 
                FROM sitcli GROUP BY 1) a 
       ON sitcli.client_id=a.client_id AND a.maxdate=sitcli.date;

Appreciate any help

alexherm
  • 1,362
  • 2
  • 18
  • 31

1 Answers1

3

You can use select first:

select first 1 t.*
from t
order by date desc, seq desc
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786