Select maximum of update number in all vouchers

Mohamed Farook 161 Reputation points
2022-12-10T06:01:33.903+00:00

Hi,

I need all vouchers in maximum of update number.

create table #temp (_Type varchar(20),_Voucher varchar(20),_Update int)
insert into #temp (_Type,_Voucher,_Update) values ('AAA','1001',1), ('AAA','1001',2), ('AAA','1001',3),
('BBB','1001',1), ('BBB','1001',2), ('BBB','1001',3),('CCC','1001',1), ('CCC','1001',2), ('CCC','1001',3)
select * from #temp
drop table #temp

Developer technologies | Transact-SQL
SQL Server | Other
{count} votes

Accepted answer
  1. Anonymous
    2022-12-12T02:34:24.5+00:00

    Hi @Mohamed Farook

    If I understand correctly, you can try this query.

    select * from   
      (select *,max(_Update)over(partition by _Type) as maximum from #temp) as t  
    where _Update = maximum;  
    

    Best regards,
    Percy Tang

    ----------

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.