Extract latest entry for each currency type from table Solution required on Microsoft SQL Server.

Here is a example of a table I have:

---------------------------------------------------------------------
| Currency Code | Starting Date           | Exchange Rate Amount    |
---------------------------------------------------------------------
| CZK           | 2014-09-10 00:00:00.000 | 27.64000000000000000000 |
| EUR           | 2015-09-01 00:00:00.000 | 1.17570000000000000000  |
| CZK           | 2015-07-30 00:00:00.000 | 28.29840000000000000000 |
| PLN           | 2015-06-16 00:00:00.000 | 5.35640000000000000000  |
| EUR           | 2016-09-01 00:00:00.000 | 1.17090000000000000000  |
| PLN           | 2015-07-30 00:00:00.000 | 5.49070000000000000000  |
---------------------------------------------------------------------


I would like to return the last entry for each [Currency Code] in a single table like so:

---------------------------------------------------------------------
| Currency Code | Starting Date           | Exchange Rate Amount    |
---------------------------------------------------------------------
| CZK           | 2015-07-30 00:00:00.000 | 28.29840000000000000000 |
| EUR           | 2016-09-01 00:00:00.000 | 1.17090000000000000000  |
| PLN           | 2015-07-30 00:00:00.000 | 5.49070000000000000000  |
---------------------------------------------------------------------


I can do it individually like this

SELECT TOP 1 [Currency Code] AS Currency, CONVERT(varchar, [Starting Date], 103) AS Date, CAST([Exchange Rate Amount] AS DECIMAL(8,3)) AS Rate
FROM myTable
WHERE [Currency Code] = 'EUR'
ORDER BY [Starting Date] DESC


This returns the following:

---------------------------------
| Currency | Date       | Rate  |
---------------------------------
| EUR      | 01/09/2016 | 1.171 |
---------------------------------


However, I would like the last entry for each currency listed in a single table.
You can use row_number() to do this, with something like this:

select [Currency Code], [Starting Date], [Exchange Rate Amount]
from (
  select *, 
  row_number() over (
       partition by [Currency Code] 
       order by [Starting Date] desc
    ) as RN
  From myTable
) X where RN = 1;


The row number will number the rows per currency (that's what partition by does) starting from the newest, and then the outer select will just take the first for each currency.