次に、2 つのテーブルがあります。
// One record per student / sport association
student_sport
StudentID
SportID
// A match is only for one sport (warning to your plural) no?
matches
SportID
MacthID
希望するもの: 1 人の生徒の場合、すべてのスポーツがすでに試合で行われています
SELECT DISTINCT StudentID, student_sport.SportID
FROM student_sport, matches
WHERE
-- Select the appropriate player
student_sport.StudentID = @StudentID
-- Search all sport played in a match and plays by the student
-- (common values sportid btw student_sport & matches)
AND student_sport.SportID = matches.SportID
または、この他の構文 (JOIN IN) を使用します (複雑なクエリが理解しやすくなるため、習得するのに適しています)
SELECT DISTINCT StudentID, student_sport.SportID
FROM student_sport
-- Search all sport played in a match and plays by the student
-- (common values sportid btw student_sport & matches)
INNER JOIN matches on student_sport.SportID = matches.SportID
WHERE
-- Select the appropriate player
student_sport.StudentID = @StudentID
ps: Jan Hudec のコメントを含む、そのための tx