Is there a better way to perform this query without using a nested subquery?
-- select all races for jockeys which have multiple regions
select distinct r.id, r.description
from jockeys_races jra inner join races r on r.id = jra.race_id
where jra.jockey_id in (
select jre.jockey_id
from jockeys_regions jre
group by jre.jockey_id
having count(*) > 1
);
Jockeys can belong to multiple regions. Jockeys can be in multiple races.
It may not be as efficient (since the product will be larger), but you can do it. Check the EXPLAIN on both.