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 can use correlated subquery

```
select * from tablename where srno in
(select max(srno) from tablename b where a.fkey=b.fkey)

```