[Solved] Does this SQL statement look right?


  • You want to display distinct values of Department Number and Department Name
  • You join Employees table with Department on Department Number
  • You join Jobs table with Employees on Job ID
  • You filter the result by excluding those Department Numbers of the entire Employee table that have a Job 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?