I have made a view of 2 tables - Department Master and Employee Master. This is the table
Emp_Id Emp_Name Salary Dept_Id Dept
1 Chandan 10000.00 1 Mechnical
2 Sudhir 11000.00 1 Mechnical
3 Rahul 20000.00 1 Mechnical
4 Kavish 15000.00 1 Mechnical
5 sapin 23000.00 2 Computer
6 Kavita 23200.00 2 Computer
7 amit 50000.00 2 Computer
I want to get Maximum salary with department name and Employee Name I used this this group by query as follows
select MAX(Emp_Salery) as Emp_Sal from V_New_Emp_Master group by Dept_Id
I am getting max salery , but when when I add Emp_Name column I get an error as followes
SQL query
select MAX(Emp_Salery),Emp_Name as Emp_Sal from V_New_Emp_Master group by Dept_Id
Error:
Msg 8120, Level 16, State 1, Line 1
Column 'V_New_Emp_Master.Emp_Name' is invalid in the select list
because it is not contained in either an aggregate function or the
GROUP BY clause.
Is there any solution for this?