I am trying to write this select statement.
My select statement consists of a join that returns all of the first and last names of my fictional employees, their department names and I am trying to group the individuals by their respective departments. This is the code I wrote:
select e.First_Name,e.Last_Name,Department_Name
from EMPLOYEES e
join DEPARTMENTS
on e.Department_Id = DEPARTMENTS.Department_Id
group by Department_Name
This is the error message I received:
Msg 8120, Level 16, State 1, Line 1 Column 'EMPLOYEES.First_Name' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
What is the best to straighten out this error?
Thank you for your help