Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL Query for Max Per Department
00:00
5 left

SQL Query for Max Per Department

MediumSQL · PostgreSQL

Problem

Write a SQL query to retrieve the maximum salary per department from two related tables.

Use the departments and employees tables. Include every department, including departments without employees or with only NULL salaries.

Output

  1. One row per department
  2. Columns: department_name and maximum_salary
  3. Sort by department_name in ascending order

Schema

departments
ColumnTypeDescription
department_idPKINTUnique department identifier
department_nameVARCHAR(100)Department name
employees
ColumnTypeDescription
employee_idPKINTUnique employee identifier
employee_nameVARCHAR(150)Employee full name
department_idINTReferenced department identifier
salaryNUMERIC(12,2)Annual employee salary
Tablesdepartmentsemployees
Interviewer

Your question is SQL Query for Max Per Department. Start with the requirements and the two tables in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.