Perhaps you can explain what you want to do. I'm pretty sure you can do it without 28 separate queries. The one you posted it not complete (no FROM clause). But I get the gist. This link might help you to articulate you particular issue better so we can offer a better suggestion for you:http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxMaybe all you need is a CASE statement?? Select studentName, SUM(CASE WHEN Grades.cat1 = 'P' THEN 1 ELSE 0 END) AS SumOfGradesCat1Pass, SUM(CASE WHEN Grades.cat2 = 'P' THEN 1 ELSE 0 END) AS SumOfGradesCat2Pass, Grades, student, course FROM ??? where student.id = course.studentId and course.id = grades.courseI