I have this query:
SELECT
course_category.id AS languageId,
course_category.code AS languageCode,
course_category.name AS languageName,
(
SELECT
SUM(gradebook_result.score)
FROM
gradebook_result
JOIN
gradebook_evaluation ON gradebook_evaluation.id=gradebook_result.evaluation_id
JOIN
gradebook_category ON gradebook_category.id=gradebook_evaluation.category_id
WHERE
gradebook_category.course_code=course_category.code
) AS languageWordsTranslated
FROM
course_category
WHERE
course_category.code != 'GEN'
ORDER BY
name
ASC
The problem occurs inside the nested SELECT where I get an error referencing the course_category table from within the SELECT on line:
WHERE
gradebook_category.course_code=course_category.code
Giving error:
Unknown column 'course_category.code' in 'where clause'
I have done this query before with other projects the only difference is that this one has joins within it. Any ideas?
EDIT: I removed the joins and hardcoded:
WHERE
course_category.code = 'ARA'
Seems like the joins mess it up, any way to fix that??
Try to do it a bit different way, using subquery and joining to it: