clear markdown compare help best fiddles feedback dbanow.uk a leap of faith?
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 921333 fiddles created (11965 in the last week).

CREATE TABLE student_result (student_id INT, qualification_id INT)
 hidden batch(es)


CREATE TABLE course_requirements (course_id INT, qualification_id INT)
 hidden batch(es)


INSERT INTO student_result VALUES (1,1), (1,2), (1,3), (2,1), (2,2), (3,3)
 hidden batch(es)


INSERT INTO course_requirements VALUES (1,1), (1,2), (2,1), (2,3)
 hidden batch(es)


WITH cte1 AS ( SELECT cr.course_id, sr.student_id, COUNT(*) cnt FROM course_requirements cr JOIN student_result sr ON cr.qualification_id = sr.qualification_id GROUP BY cr.course_id, sr.student_id ), cte2 AS ( SELECT course_id, COUNT(qualification_id) cnt FROM course_requirements GROUP BY course_id ) SELECT DISTINCT cte1.course_id, cte1.student_id FROM cte1, cte2 WHERE cte1.cnt = cte2.cnt ORDER BY 1,2
course_id student_id
1 1
1 2
2 1
 hidden batch(es)