# Top Salaries by Department — SQL Interview Question

Aced (formerly Exponent) publishes a public search API over its indexed pages; the guide is at https://www.aced.io/agents/agent-access.

Source: https://www.aced.io/questions/3045/top-salaries-by-department
Source observed: 2026-11-04T21:34:30.833Z
Last checked: 2026-11-04T21:34:30.833+00:00
Indexed: 2026-11-05T02:40:08.009+00:00

---

# Top Salaries by Department

**Difficulty:** Hard  
**Format:** SQL coding question  
**Interview activity:** 6 interviews; last asked 7 months ago  
**Roles:** [Data Engineer](https://www.aced.io/questions?role=data-engineer), [Product Manager](https://www.aced.io/questions?role=pm), [Data Scientist](https://www.aced.io/questions?role=data-science), [Data Analyst](https://www.aced.io/questions?role=data-analyst)  
**Companies:** [Meta](https://www.aced.io/questions?company=meta-facebook), [Tesla](https://www.aced.io/questions?company=tesla)  
**Categories:** [Coding](https://www.aced.io/questions?type=coding), [SQL](https://www.aced.io/questions?type=sql)

## Question

Given the database schema below, write a SQL query to fetch the top-earning employee by department, ordered by department name.

## Database schema

```text
employees                             projects
+---------------+---------+           +---------------+---------+
| id            | int     |<----+  +->| id            | int     |
| first_name    | varchar |     |  |  | title         | varchar |
| last_name     | varchar |     |  |  | start_date    | date    |
| salary        | int     |     |  |  | end_date      | date    |
| department_id | int     |--+  |  |  | budget        | int     |
+---------------+---------+  |  |  +---------------+---------+
                              |  |  |
departments                  |  |  |  employees_projects
+---------------+---------+  |  |  |  +---------------+---------+
| id            | int     |<-+  |  +--| project_id    | int     |
| name          | varchar |     +-----| employee_id   | int     |
+---------------+---------+           +---------------+---------+
```

The schema includes:

- `employees`: `id`, `first_name`, `last_name`, `salary`, and `department_id`.
- `departments`: `id` and `name`.
- `projects`: `id`, `title`, `start_date`, `end_date`, and `budget`.
- `employees_projects`: `project_id` and `employee_id`, linking employees with projects.

## Required result format

```text
department_name | employee_id | first_name | last_name | salary
----------------+-------------+------------+-----------+------
varchar         | int         | varchar    | varchar   | int
```

The result must contain the department name, the highest-earning employee's ID, first name, last name, and salary, with departments ordered by name.

## Access and coding workspace

Detailed company statistics require [Upgrade](https://www.aced.io/upgrade?src=questions). The page includes Question, Solution, and Community tabs; the Community tab is labeled `41`. The SQL editor provides Editor and Share views, with Output, Test Results, and Console areas. Running code requires [signing up](https://www.aced.io/signup?src=lesson).

## Interview experience

One shared experience is associated with this question:

- **[Meta · 7 months ago — Data Engineer](https://www.aced.io/experiences/meta-facebook-data-engineer-interview-0b5b15)** — “The technical round covered SQL and data structures. The SQL portion felt more familiar, while the linked list question required additional thought. Time management was the biggest challenge.”

## Related questions

- [Rank Salary by Department](https://www.aced.io/questions/4379/rank-salary-by-department)
- [Find Revenue by Department](https://www.aced.io/questions/3965/find-revenue-by-department)
- [Find Customers by Department](https://www.aced.io/questions/3966/find-customers-by-department)

## Related courses

### [Data Analyst Interview Prep](https://www.aced.io/courses/data-analytics)

![Data Analyst Interview Prep](https://images.ctfassets.net/x78yjrjc11pq/72OTqij57b2TklhaD2vrdV/be0dae6242904970d1696e5a4d858e18/AdobeStock_1357126576.jpeg?w=800&h=800&fm=webp&q=75)

We help candidates prepare for data analyst interviews across product, marketing, and business analyst roles through real take-home case studies, technical and dashboarding practice, and strategies from interviewers at top technology companies and startups.

### [Data Science Interview Prep](https://www.aced.io/courses/data-science)

![Data Science Interview Prep](https://images.ctfassets.net/x78yjrjc11pq/3U4C5C0OkDR0UeGch4AmlE/7ad489430b676a088cb973307fe77884/Data_Science_Interview_Prep_Course.jpeg?w=800&h=800&fm=webp&q=75)

We prepare candidates for data science roles at Google, Amazon, Microsoft, Meta, Apple, and other companies with mock interviews, frameworks, and advice from senior candidates. Practice covers statistics, experimentation, coding, SQL, machine learning, behavioral interviews, and more.

## About Aced

We are Aced, formerly Exponent. We provide interview-preparation courses, practice questions, interview experiences, coaching, resume review, salary negotiation, job referrals, and related resources for technology and business roles. Browse [all questions](https://www.aced.io/questions), [SQL questions](https://www.aced.io/questions?type=sql&filterBy=codeEditor&src=nav), [Data Engineering questions](https://www.aced.io/questions?role=data-engineer&type=data-pipeline-design&type=system-design&type=sql&type=data-modeling&src=nav), or [all courses](https://www.aced.io/courses?src=nav).

---

[Read this page’s summary](https://www.aced.io/agents/api/public/v1/page-tldr?url=https%3A%2F%2Fwww.aced.io%2Fquestions%2F3045%2Ftop-salaries-by-department&trace=t_679ff9ab98f3)

## Ask a follow-up about this page

Need a more specific answer? Ask the exact question you have. It returns a fresh, cited answer from Aced (formerly Exponent)’s knowledge base. No account or API key required.

Open this URL with your own question, URL-encoded. Include your question in q. All research inputs are optional; no account or setup.

`GET https://www.aced.io/agents/agent/faq?q={question}&trace=t_679ff9ab98f3`

[Tool guide and examples](https://www.aced.io/agents/agent-access) · [OpenAPI](https://www.aced.io/agents/api/public/v1/openapi.json) · [Page TLDR form](https://www.aced.io/agents/agent-tools/page-tldr?url=https%3A%2F%2Fwww.aced.io%2Fquestions%2F3045%2Ftop-salaries-by-department). Opening a form does not execute a tool.