Skip to main contentSkip to solution

Consider the 'Employee' table given below:

Emp_ IdNameDeptSalary
101AsthaHR80000
102SumitIT50000
103NidhiMarketing40000
104AnandIT55000
105JyotiHR70000

Which of the following SQL query will find the name of the employee with the highest salary?

Solution

✅ Correct Option: 4

Option 4 sorts the rows by Salary in descending order, so the highest salary comes first. LIMIT 1 then keeps only that first row. Here it returns Astha (80000).


Option 1: an aggregate function like MAX() cannot be used directly in a WHERE clause. The syntax WHERE = Salary is also invalid.

Option 2: the subquery SELECT Salary AS max(Salary) is invalid, because an alias cannot be a function call. The correct form is WHERE Salary = (SELECT MAX(Salary) FROM Employee).

Option 3: GROUP BY Employee uses the table name, not a column, and HAVING Salary = MAX(Salary) compares each row with itself. It is invalid and would not find the top salary.

WHERE filters individual rows before grouping and cannot use aggregates. HAVING filters groups after grouping.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question