Reputation: 35
I have this query and I want to optimize it. I use a SELECT and a subquery, and I'd like to use only one SELECT if possible.
Does anyone have any idea about it?
Thank you in advance
SELECT c.*
FROM course AS c
JOIN student_course AS sc ON c.id = uc.course_id
WHERE sc.student_id = '5' AND c.level = (SELECT MAX(level)
FROM course
JOIN student_course ON c.id = sc.course_id)
GROUP BY c.category_id
Upvotes: 1
Views: 63
Reputation: 5588
SELECT c.*
FROM course AS c
JOIN student_course AS sc
ON c.id = sc.course_id
WHERE sc.student_id = '5'
GROUP BY c.category_id
having c.level = MAX(sc.level)
Upvotes: 3