Magicsheet logo

Project Employees II

Easy
25%
Updated 8/1/2025

Asked by 1 Company

Topics

Project Employees II

What is this problem about?

The Project Employees II SQL problem asks you to find the project(s) with the most employees. If there's a tie, return all tied projects. This easy SQL problem tests GROUP BY, COUNT, and then finding the maximum count. The database interview pattern is demonstrated.

Why is this asked in interviews?

Meta asks this as a "find max group" SQL problem — requiring two steps: count per group, then filter for the maximum count. It tests the HAVING with subquery pattern or dense rank approach.

Algorithmic pattern used

COUNT + subquery for max. SELECT project_id FROM Project GROUP BY project_id HAVING COUNT(employee_id) = (SELECT COUNT(employee_id) FROM Project GROUP BY project_id ORDER BY COUNT(employee_id) DESC LIMIT 1).

Or: SELECT project_id FROM Project GROUP BY project_id HAVING COUNT(*) >= ALL (SELECT COUNT(*) FROM Project GROUP BY project_id).

Example explanation

Project: proj1 has 3 employees, proj2 has 3 employees, proj3 has 1 employee. Max employee count = 3. Projects with 3: proj1, proj2. Result: [proj1, proj2].

Common mistakes candidates make

  • Using LIMIT 1 which misses tied projects.
  • Not using a subquery/max approach to find the maximum.
  • Grouping on wrong column.
  • Using >= instead of = in HAVING.

Interview preparation tip

"Find group with max aggregate" requires a two-step approach: (1) compute aggregate per group, (2) filter for max. The HAVING + max subquery pattern handles ties correctly. Alternative: DENSE_RANK() OVER (ORDER BY COUNT DESC) WHERE rank=1. Always consider ties in "find maximum" SQL problems. Practice: "products with highest sales," "categories with most items," "months with peak activity."

Similar Questions