- You want to display distinct values of
Department NumberandDepartment Name - You join
Employeestable withDepartmentonDepartment Number - You join
Jobstable withEmployeesonJob ID - You filter the result by excluding those
Department Numbersof the entireEmployeetable that have aJob IDmatching the pattern%SA_REP%
In my opinion you don’t need
- the join with the
Jobstable - the join with the
Employeestable - 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?