Skip to content

Instantly share code, notes, and snippets.

@mble
Last active June 5, 2017 21:14
Show Gist options
  • Save mble/b5d1aba77b5a9bc5bcb9963ec962afde to your computer and use it in GitHub Desktop.
Save mble/b5d1aba77b5a9bc5bcb9963ec962afde to your computer and use it in GitHub Desktop.
Relational Divison
-- Fetch all films two actors appeared in together and order alphabetically
-- film, film_actor and actor tables, with a simple schema
select f.title
from film f
inner join (
select fa.film_id
from film_actor fa
where fa.actor_id in (105, 122)
group by fa.film_id
having count(*) = (
select count(*)
from actor
where actor.actor_id in (105, 122)
)) f2 on f.film_id = f2.film_id
order by f.title
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment