SQL Interview Questions · Question 01

Write a query to display all Engineering employees ordered by salary from highest to lowest?

Interview preparation resource from Gate Smashers.

Interview-ready answer

SELECT employee_name, salary FROM Employees WHERE department = 'Engineering' ORDER BY salary DESC;

Employees
employee_idemployee_namedepartmentsalarymanager_id
101AaravEngineering95000105
102MeeraEngineering72000105
103KabirSales65000106
104IshaSales92000106
105RohanEngineering90000NULL
106NehaSales88000NULL
SQL querysql
SELECT employee_name, salary
FROM Employees
WHERE department = 'Engineering'
ORDER BY salary DESC;
Understand it clearly

Direct answer

Filter the Employees table to Engineering rows and sort the result by salary in descending order. The SQL query below returns employee_name and salary for Engineering employees with the highest salaries first.

How it works

The query uses a WHERE clause to restrict rows to the Engineering department and an ORDER BY clause to place the highest salary first.

  • Filter: WHERE removes employees from other departments before the final result is returned.
  • Sort: ORDER BY salary DESC places the highest salary first.

Dataset / Schema

The query operates on the Employees table which contains the following columns: employee_id, employee_name, department, salary, manager_id. The sample data from the supplied material is shown in the table block below.

Deterministic ordering (note)

If multiple employees share the same salary and you need a deterministic result order, add a second sort key such as employee_id to ORDER BY (for example: ORDER BY salary DESC, employee_id).