I have two tables:
entry
id
......
individual
id,
entry_id,
code
where entry
has a one to many relation to individual
.
I want to select all individuals that belong to an entry that contains more than 3 individuals which have code between A=10 and B=15
I wrote this query and it works:
select entry_id,id
from individual as i
where i.entry_id in
(select entry_id
from individual as v
where v.code between 10 and 15
group by entry_id
having count(*) > 3 )
but it's slow.
So I want to try to convert it to use a join instead of a nested query.