Last post Oct 28, 2018 04:01 PM by mgebhard
Oct 28, 2018 03:15 PM|JagjitSingh|LINK
I have below code and i want record with Max Date from Table 2
SELECT * FROM dbo.Employee T1 Left join dbo.Employee_Details T2
on T1.EmployeeID = T2.EmployeeID order by T1.EmployeeID
Oct 28, 2018 04:01 PM|mgebhard|LINK
Example using AdventureWorks and Min Max.
FROM [Person].[Person] AS p
CROSS JOIN (
SELECT MAX([BusinessEntityID]) as MaxId, MIN([BusinessEntityID]) AS MinId
) AS p2
WHERE p.[BusinessEntityID] = p2.MaxId OR p.[BusinessEntityID] = p2.MinId
BTW, this is a very common scenario for which there are many online examples.