- You want to display distinct values of
Department Number
andDepartment Name
- You join
Employees
table withDepartment
onDepartment Number
- You join
Jobs
table withEmployees
onJob ID
- You filter the result by excluding those
Department Numbers
of the entireEmployee
table that have aJob ID
matching the pattern%SA_REP%
In my opinion you don’t need
- the join with the
Jobs
table - the join with the
Employees
table - you could maybe see if one of the other users’ suggestions can bring performance improvement
SELECT DISTINCT departments.department_no,
departments.department_name
FROM departments
WHERE departments.department_no NOT IN (SELECT DISTINCT department_no
FROM employees
WHERE employees.job_id LIKE '%SA_REP%'
);
solved Does this SQL statement look right?