I'm trying to find matches where the referee in the match (who is an official) also provides medical services to both the home and away teams (please refer to below relational diagram).
I've tried this, but it returns no records:
select matches.id,
matches.home,
matches.away,
matches.referee
from matches
join officials on officials.staffid = matches.referee
join medicalservices on medicalservices.team in (matches.home, matches.away)
where medicalservices.team = matches.home
and medicalservices.team = matches.away;
I'm guessing it doesn't return records because of the last two lines, but I don't know how else I can ensure that the same official provides medical services to both teams playing.
Here is the relational diagram for reference:
