Created
December 29, 2017 02:22
-
-
Save francisngo/459e43a24ad6312d85430f4b6ee75b56 to your computer and use it in GitHub Desktop.
A SQL select statement with multiple joins
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
/* | |
Sample Data | |
----------- | |
movie | |
------------------------------------------------ | |
id title yr director budget gross | |
actor | |
----------- | |
id name | |
casting | |
----------------------- | |
movieid actorid ord | |
*/ | |
-- List the film title and the leading actor for all of the films 'John Travolta' played in. | |
SELECT movie.title, actor.name | |
FROM movie JOIN casting ON (movie.id = casting.movieid AND casting.ord = 1) | |
JOIN actor ON (actor.id = casting.actorid) | |
WHERE movie.id IN (SELECT casting.movieid FROM casting WHERE casting.actorid IN (SELECT actor.id FROM actor WHERE name = 'John Travolta')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment