Returning a unique set of values from a table

MrFlinstone 501 Reputation points
2021-01-19T14:38:45.793+00:00

Hi All.

I have a table log as per below.

58047-image.png

What I will like to do is return the last 3 release no's ordering by the release data.

In the case of the example below, that would be 77,66 and 55

The query below is not correct.

select releaseno  
from  
(select distinct releaseno, releasedate  
from release_log  
order by releasedate desc) last_3_release_no_extract  
  
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,562 questions
0 comments No comments
{count} votes

1 additional answer

Sort by: Most helpful
  1. Tom Cooper 8,466 Reputation points
    2021-01-19T14:49:34.583+00:00
    ;With cte As
    (Select releaseno, 
      Dense_Rank() Over(Order By releaseno Desc) As rk
    From release_log)
    Select releaseno
    From cte
    Where rk <= 3;
    

    Tom

    0 comments No comments