I was wondering if anyone could help.
I am trying to write some code that returns a list of the latest hires based upon Jobtitle using the Adventureworks2012 databse.
So far, I have the following:
SELECT DISTINCT HREDH.BusinessEntityID,
HRE.JobTitle,
hre.HireDate
FROM [HumanResources].[EmployeeDepartmentHistory] HREDH
INNER JOIN HumanResources.Employee HRE ON HREDH.BusinessEntityID = HRE.BusinessEntityID
AND hre.BusinessEntityID = (
SELECT TOP 1 BusinessEntityID
FROM HumanResources.Employee hre2
WHERE hre2.JobTitle = hre.JobTitle
ORDER BY HireDate DESC
)
ORDER BY HRE.JobTitle
This appears to work fine, but I am sure there is a better way to do it (without the use of SELECT DISTINCT at the beginning of the statement)
I am trying my best to learn SQL by myself, so any help from the vast pool of knowledge on here would be greatly appreciated!
Thanks,