Prepin
Log in

Highest Salaries by Department

Approach / Explanation

The interviewer has posed a question concerning SQL queries, specifically inquiring whether you can formulate a query that retrieves the maximum salaries for each department from a specified employee table that contains their departments and salaries. To effectively respond to this inquiry, you should be familiar with and apply several important SQL concepts, including: GROUP BY : This clause is utilized to organize rows that share the same values in designated columns into aggregated data. MAX() function : This function is employed to return the highest value from the selected column. In relation to the question, you will need to: Utilize the GROUP BY clause to categorize the employees by their department. Employ the MAX() function to determine the highest salary within each department.

Suggested Answer

Take a look at the following table containing employee information: EMPLOYEE ----------------------------- ID | Employee_name | Salary | Department ----------------------------- 1 | John | 5000 | HR 2 | Mike | 6000 | IT 3 | Sara | 5500 | HR 4 | Chris | 7000 | IT 5 | Kate | 6500 | Marketing 6 | Lisa | 6800 | Marketing To retrieve the highest salaries by department using SQL, you can execute a query like the following: SELECT Department , MAX ( Salary ) as Top_Salary FROM Employee GROUP BY Department ; This query will provide the department along with the highest salary within each department.

Alternative Answer

Take a look at the following employee data table: EMPLOYEE ----------------------------- ID | Employee_name | Salary | Department ----------------------------- 1 | Alex | 7000 | Finance 2 | Bella | 8000 | Operations 3 | Charlie | 7500 | Finance 4 | Darryl | 9000 | Operations 5 | Ellie | 6500 | Sales 6 | Freddie | 8000 | Sales To retrieve the highest salaries by department using SQL, the query would be structured as follows: SELECT Department , MAX ( Salary ) as Highest_Salary FROM Employee GROUP BY Department ; This query will provide the department alongside the maximum salary in each department. The term 'Highest_Salary' serves as an alias to enhance the readability of the result set.

Question Details

Difficulty & Category

Medium
sql

Product

For CandidatesFor RecruitersCompaniesBrowse JobsInterview QuestionsDeep ProfileSkill AssessmentOpportunity Matching
Prepin.ai

© 2026 Prepin LLC · Philadelphia, PA · All rights reserved.