79567659

Date: 2025-04-10 22:26:41
Score: 1.5
Natty:
Report link

This query yields the same results, but runs much faster (less than 0.0015s); where as the original query, with multiple sub-queries, never took less than 0.0025s.

SELECT DISTINCT `Pos Dept`, `Dept Desc` 
FROM collData JOIN depts ON collData.`Pos Dept`= depts.dept_code
WHERE collData.`Dept Desc` <> depts.dept_name
ORDER BY `Pos Dept`;

Thanks for the guidance @Barmar.

I used this page to design the JOIN-based query: https://dev.mysql.com/doc/refman/5.7/en/rewriting-subqueries.html

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: J. Robert West