You are given two tables: Project and Employee.
The Project table contains information about which employees are working on which projects, with a composite primary key of (project_id, employee_id).
The Employee table contains employee details including their experience years.
Task: Write a SQL query to find all projects that have the most employees. Return the result in any order.
Table Schema
| Column Name | Type | Description |
|---|---|---|
project_id
PK
|
int | Project identifier |
employee_id
PK
|
int | Employee identifier (foreign key to Employee table) |
| Column Name | Type | Description |
|---|---|---|
employee_id
PK
|
int | Employee identifier (primary key) |
name
|
varchar | Employee name |
experience_years
|
int | Years of experience |
Input & Output
| project_id | employee_id |
|---|---|
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| 2 | 1 |
| 2 | 4 |
| employee_id | name | experience_years |
|---|---|---|
| 1 | Khaled | 3 |
| 2 | Ali | 2 |
| 3 | John | 1 |
| 4 | Doe | 2 |
| project_id |
|---|
| 1 |
Project 1 has 3 employees (1, 2, 3) while Project 2 has 2 employees (1, 4). Since 3 is the maximum number of employees, only Project 1 is returned.
| project_id | employee_id |
|---|---|
| 1 | 1 |
| 1 | 2 |
| 2 | 3 |
| 2 | 4 |
| employee_id | name | experience_years |
|---|---|---|
| 1 | Alice | 3 |
| 2 | Bob | 2 |
| 3 | Charlie | 1 |
| 4 | David | 2 |
| project_id |
|---|
| 1 |
| 2 |
Both Project 1 and Project 2 have exactly 2 employees each. Since both projects tie for the maximum number of employees, both are returned in the result.
| project_id | employee_id |
|---|---|
| 1 | 1 |
| 1 | 2 |
| employee_id | name | experience_years |
|---|---|---|
| 1 | John | 5 |
| 2 | Jane | 3 |
| project_id |
|---|
| 1 |
Only one project exists with 2 employees, so it automatically has the most employees and is returned.
Constraints
-
1 ≤ project_id ≤ 100 -
1 ≤ employee_id ≤ 100 -
1 ≤ experience_years ≤ 20 -
nameconsists of lowercase and uppercase English letters