title: MYSQL case if join is meant than perform subquery loop?
body: <p>Sorry if the title is confusing I'm not sure the correct approach here.</p>
  
  <p>This may be confusing but I have the following query to generate a temp table of students and I want to link this to the second query :
  <a href="http://pastebin.com/mHybk9c7" rel="nofollow noreferrer">http://pastebin.com/mHybk9c7</a></p>
  
  <p>And I have the following stored procedure - This proc grabs students completion results via a set of scalar subqueries.
  <a href="http://pastebin.com/WF7evQSH" rel="nofollow noreferrer">http://pastebin.com/WF7evQSH</a></p>
  
  <p>The problem is I can pull an individual students grades - and I can pull every class and every students activities (about 100m records...) but I can't pull on the class level. I can't do this because of the subquery and I can't seem to find a workaround</p>
  
  <p>tldr: I run the second query to pull every student and every course grades. Or I can add a where to the main query or subquery to get a specific student. But I want to get every student for a specific course (based on the temp table)</p>