Find Employees Working on Projects
A company has two systems: one for employee details and another for project assignments. We need to identify which employees are currently involved in any project.
Tables:
employees(employee_id, employee_name)project_assignments(assignment_id, employee_id, project_name)
Return the employee_name for all employees who have at least one entry in the project_assignments table. The results should be ordered alphabetically by employee name.
If an employee is not assigned to any project, they should not appear in the result. If multiple employees have the same name, they should appear as separate rows if their IDs are distinct. Ties in ordering are handled by the employee_name itself.
Tables
CREATE TABLE employees (
employee_id integer PRIMARY KEY,
employee_name varchar(100) NOT NULL
);
CREATE TABLE project_assignments (
assignment_id integer PRIMARY KEY,
employee_id integer NOT NULL,
project_name varchar(100) NOT NULL
);Example data
INSERT INTO employees (employee_id, employee_name) VALUES (1, 'Alice'), (2, 'Bob'), (3, 'Charlie'), (4, 'David'), (5, 'Eve'); INSERT INTO project_assignments (assignment_id, employee_id, project_name) VALUES (101, 1, 'Project Alpha'), (102, 2, 'Project Beta'), (103, 1, 'Project Gamma'), (104, 3, 'Project Delta'), (105, 5, 'Project Epsilon');
Your query is also checked on hidden datasets with different data.
Hints
-- Select employee names who are assigned to projects
SELECT e.employee_name
FROM employees e
Your query runs on the example tables shown with the problem, then on hidden datasets when you submit.
Write standard SQL. MySQL habits work too: IFNULL, IF, YEAR(), DATE_FORMAT, GROUP_CONCAT, `backticks` and LIMIT 5, 10. It runs on PostgreSQL, so integer division keeps whole numbers (5 / 2 = 2): write 5.0 / 2 for 2.5.