What’s wrong in the following query?

SELECT Name, MaxSal = Max(Salary)
FROM tblEmployees;

 Posted by Rajnilari2015 on 10/23/2016 | Category: Sql Server Interview questions | Views: 2722 | Points: 40

It doesn’t have a GROUP BY clause. The Name should be in the GROUP BY clause. The correct query is

SELECT Name, MaxSal = Max(Salary) 

FROM tblEmployees
Group By Name

- OR -

Select Name, MaxSal = MAX(Salary) OVER (PARTITION BY Name) 

FROM tblEmployees

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response