select lastname, firstname
from person
group by lastname, firstname
having 50 >=
(select count(p.personid) from filmparticipation x, film f, person p
where f.filmid = x.filmid and
x.personid = p.personid and
x.parttype = 'cast'
);
Short intro, this is based on a movie database. With this query I’m supposed to get the actors that are featuring in movies more thann 50 times.
Details to know, film contains filmid, then parsed to filmparticipation where there are some personids related to a movie. p.personid contains lastname and firstname.
Any guidance will be preciated 🙂
You don’t actually need the
filmtable for anything in the query, so you can leave it out. You should also remember that actors may play multiple roles in one film, and can thus have multiple entries per film in thefilmparticipationtable. To catch this, use a subquery withDISTINCT.