There is a result set where all the records are unique columns like this .
I only want to display the records with newer dates if there is another record which belongs to the same BusinessID.
My query to get this result is
SELECT
FirstName,
LastName,
Department,
StartDate,
Title,
PhoneNumber,
BusinessEntityID
FROM
(SELECT
E.BusinessEntityID,
H.FirstName,
H.LastName,
H.Title,
H.Department,
E.PhoneNumber,
E.CountryRegionName,
E.PostalCode,
H.StartDate
FROM
CS120Exam_EmployeeDepartmentHistory H
JOIN
CS120Exam_Employee E
ON
E.BusinessEntityID=H.BusinessEntityID ) x
ORDER BY BusinessEntityID
And the result is
BusinessID FirstName LastName Department StartDate
----------- --------- -------- ---------- ----------
1 aaa mate staff 2002-02-02 <----- DO NOT want this
1 aaa mate admin 2004-03-05
2 john mate admin 2001-03-06
3 sun kent admin 2004-03-05
4 bbb clark staff 2006-02-02 <----- DO NOT want this
4 bbb clark admin 2009-03-05
You need a sub-select to find the latest date for each
BusinessEntityID. Try this (untested, of course):