Consider the 'Employee' table given below:
Emp_ Id Name Dept Salary 101 Astha HR 80000 102 Sumit IT 50000 103 Nidhi Marketing 40000 104 Anand IT 55000 105 Jyoti HR 70000
Which of the following SQL query will find the name of the employee with the highest salary?
Consider the 'Employee' table given below:
| Emp_ Id | Name | Dept | Salary |
|---|---|---|---|
| 101 | Astha | HR | 80000 |
| 102 | Sumit | IT | 50000 |
| 103 | Nidhi | Marketing | 40000 |
| 104 | Anand | IT | 55000 |
| 105 | Jyoti | HR | 70000 |
Which of the following SQL query will find the name of the employee with the highest salary?
Solution
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.
Related questions:
2026: 23 May Shift 1
2026: 31 May Shift 1
2026: 26 May Shift 1
2026: 19 May Shift 1