Find Employees Working on ProjectsEasy

Find Employees Working on Projects

EasySQLPractice library · +10 XPinner joinsqlemployees

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