Last active
June 5, 2017 21:14
-
-
Save mble/b5d1aba77b5a9bc5bcb9963ec962afde to your computer and use it in GitHub Desktop.
Relational Divison
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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