Reputation: 13
I'm trying to find employees that are less than 10 years from the hire date but when I run the query my employees keep repeating. I do not know where I'm messing up. This is what I have tried so far. Thanks. Also I'm using MS SQL
SELECT CONCAT('',FirstName,' ',MiddleName,' ',LastName) AS FullName
FROM Person.Person, HumanResources.Employee
WHERE HireDate < DATEADD(Year, -10, GETDATE()) ;
/* DATEDIFF(YEAR, HireDate, GETDATE()) < 10 */
Upvotes: 0
Views: 597
Reputation: 1269563
Never use commas in the FROM
clause. Always use proper, explicit, standard JOIN
syntax:
SELECT CONCAT('', FirstName, ' ', MiddleName, ' ', LastName) AS FullName
FROM Person.Person p JOIN
HumanResources.Employee e
ON p.? = e.?
WHERE HireDate < DATEADD(Year, -10, GETDATE()) ;
You don't provide enough information to specify the JOIN
conditions. But something like:
ON p.personid = e.personid
Upvotes: 4