I have 3 columns which are shop_id
, shop_number
and insert_date
. I want to get the list according to descending insert_date
s by making unique shop_id
, shop_number
.
shop_id shop_number INSERT_DATE
4 8 2021-06-29 08:37:03
4 2 2021-06-27 16:37:03
4 8 2021-06-28 16:37:03
6 1 2021-06-29 16:37:03
7 9 2021-06-30 09:37:03
6 1 2021-06-30 11:37:03
7 9 2021-06-27 16:37:03
What I expect
shop_id shop_number INSERT_DATE
6 1 2021-06-30 11:37:03
7 9 2021-06-30 09:37:03
4 8 2021-06-29 08:37:03
4 2 2021-06-27 16:37:03
I tried the following but it doesn't yield expected result.
select shop_id, shop_number, INSERT_DATE
from mytablename with(NOLOCK)
where shop_number is not null
group by shop_id, shop_number
order by INSERT_DATE desc