top of page

SSMS How to pull most recent information

So you have been assigned a task to pull data from a table that gets updated often, and you want to pull the most recent information? What now?


My simple solution to that would be using the ROW_NUMBER method. It would basically place a row number based off on your partition and order.


  • Partition - will your unique identifier(s) that you want your data to be parted by

  • Order by - will be in what order do you want your rows to be sorted by

Asc = ascending order

Desc = descending order


If you look at my example below, you will see that I had partitioned the data ID, and the most recent date had been returned a RowNum value of 1, then the subsequent dates had been given values based off on the order.


As usual, there are other ways to do this, but this is by far my favorite because it is easier for other people who is just starting out to understand what is going on.


Good luck and I hope this helps!







0 comments

Recent Posts

See All

Comments


bottom of page