Im having trouble mergin 3 tables into a query. It works with 2 fine but when I try add the Persons email address into it, it fails see below:
SELECT HumanResources.EmployeePayHistory.BusinessEntityID, Rate, HumanResources.Employee.LoginID, Person.EmailAddress.EmailAddress, JobTitle
From HumanResources.EmployeePayHistory, Person.EmailAddress.EmailAddress
INNER JOIN HumanResources.Employee,Person.EmailAddress.EmailAddress
ON HumanResources.EmployeePayHistory.BusinessEntityID = HumanResources.Employee.BusinessEntityID and HumanResources.Employee.BusinessEntityID = Person.EmailAddress.BusinessEntityID
ORDER BY BusinessEntityID DESC;
ERROR:
Msg 102, Level 15, State 1, Line 5
Incorrect syntax near ','.
Fixed:
SELECT HumanResources.Employee.BusinessEntityID, HumanResources.Employee.LoginID, Person.EmailAddress.EmailAddress, HumanResources.EmployeePayHistory.Rate
FROM Person.EmailAddress INNER JOIN HumanResources.Employee ON Person.EmailAddress.BusinessEntityID = HumanResources.Employee.BusinessEntityID
INNER JOIN HumanResources.EmployeePayHistory ON HumanResources.Employee.BusinessEntityID = HumanResources.EmployeePayHistory.BusinessEntityID
ORDER BY BusinessEntityID DESC;