Interview Question

Find highest salary per department

Use GROUP BY department and MAX salary for one value per group.

💡 Concept ✅ Quick Revision 🗃️ SQL

Answer

The highest salary per department can be calculated with MAX and GROUP BY. • GROUP BY creates one group for each department. • MAX returns the largest non-null salary in each group. • A different query is needed when employee details tied for the maximum are required.

💡 SQL Example

SELECT department_id, MAX(salary) AS highest_salary FROM employees GROUP BY department_id;

Result

One maximum salary per department

⚡ Quick Revision

Use GROUP BY department and MAX salary for one value per group.