I have the following query. I need information from a table but there are no keys that link these two tables together, and there isn't really a way that it makes sense to reference the other table from either table.
My Query:
SELECT COUNT(*)
FROM courses as c
WHERE c.StartYear = 2016
AND c.student_id IN (SELECT DISTINCT p.student_id
FROM programs AS p
WHERE p.StartYear = 2016
AND p.program_code NOT LIKE "M%")
This Query takes about 5 seconds to execute, which is way too long. Is there a better way to do this?
Server: MySQL Server version: 5.6.35
)` That's almost exactly a join on `student_id`... Perhaps you would benefit from showing us a dumy set of dat with the expected results that you're looking for?
– MatBailie Jul 04 '18 at 18:30