This was my original question:
After using Mitch Wheat’s example (and taking his well deserved admondishment), I added a column to my DEPARTMENT table in my database and implemented this code:
ALTER TABLE DEPARTMENTS
ADD Salary money
GO
select First_Name, Last_Name, department_Name
from Employees e join
(select Department_Name,AVG(Salary) AS averageSalary
from DEPARTMENTS d
join Employees e ON e.Department_Id=d.Department_Id
group by Department_Name) ds
on ds.averageSalary=e.Employee_Id
where e.salary>ds.AverageSalary
However, I still got this error:
Msg 207, Level 16, State 1, Line 8
Invalid column name 'salary'.
Why does SALARY continues to be an invalid column name?