Incorrect syntax near INNER. Expecting ID

SELECT Outer.JobId FROM JobHistory  Outer
INNER JOIN
(
    SELECT TOP 10 JobId AS JobId, MAX(UpdateDate) AS UpdatedDate
    FROM JobHistory 
    GROUP BY JobId
) Sub
ON Outer.JobId = Sub.JobId

>Solution :

Outer is a keyword in sql server, so avoid using this as alias

SELECT JH.JobId FROM JobHistory JH
INNER JOIN
(
    SELECT TOP 10 JobId AS JobId, MAX(UpdateDate) AS UpdatedDate
    FROM JobHistory 
    GROUP BY JobId
) Sub
ON JH.JobId = Sub.JobId

Leave a Reply