I have a table like:

```
id  fkey  srno  remark  date
1   A001  1
2   A001  2
3   A002  1
4   A003  1 
5   A002  2

```

I want distinct latest record based on max srno like

```
2  A001  2
4  A003  1
5  A002  2

```
['https://Stackoverflow.com/questions/53405895', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4337261/']
use window function `row_number()`

```
select * from (
select *,row_number() over(PARTITION by fkey order by srno desc) rn from table1 t1 
) t where rn=1

```

you can write it by using cte

```
with cte as
(
    select *,row_number() over(PARTITION by fkey order by srno desc) rn from 
    table_name t1
) select * from cte where rn=1

```
You may use a subquery with an `IN` operator

```
with tab(id, fkey, srno) as 
(
 select 1,'A001',1 union all
 select 2,'A001',2 union all    
 select 3,'A002',1 union all
 select 4,'A003',1 union all    
 select 5,'A002',2   
)
select *
  from tab
 where ( fkey, srno ) in
 (
  select fkey, max(srno)
    from tab
   group by fkey
 );

id  fkey    srno
2   A001     2
4   A003     1
5   A002     2

```

[***Rextester Demo***](https://rextester.com/KPF2258)