List only the latest records from a date column

Product:

Microsoft SQL server 2016

Issue:

How list only the latest rows with the same date in the update column?

Solution:

Create a view – who will only list the latest row based on the date column;

CREATE VIEW [DM].[AccountView-Latest]
AS
SELECT [key_dimAccount]
,[Name]
,[InsertDate]
,[UpdateDate]
FROM [DM].[dimAccount]
WHERE UpdateDate = ( SELECT MAX(UpdateDate) FROM [DM].[dimAccount ] )

The where statement will only take the latest date (max) from the updatedate column – should give a list with only the records that are updated at same date.

 

More Information:

https://www.w3resource.com/sql/aggregate-functions/max-date.php

https://www.w3schools.com/sql/func_sqlserver_getdate.asp