Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 6_join.sql
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ SELECT game.mdate,
ELSE 0
END) AS score2
FROM game
JOIN goal
LEFT JOIN goal
ON (game.id = goal.matchid)
GROUP BY game.id
ORDER BY game.mdate, goal.matchid
ORDER BY game.mdate, goal.matchid
24 changes: 22 additions & 2 deletions 7_more_join_operations.sql
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,22 @@ GROUP BY actor.name
HAVING COUNT(*) >= 30;

-- # 15. List the 1978 films by order of cast list size.
SELECT movie.title, COUNT(*)
SELECT movie.title, COUNT(*)
FROM movie
JOIN casting
ON movie.id = casting.movieid
WHERE movie.yr = 1978
GROUP BY movie.id
ORDER BY COUNT(*) DESC
-- # Above code gets wrong in MySQL. We have to do some
-- # modifictation with it.
-- SELECT movie.title, COUNT(*) As actors
-- FROM movie
-- JOIN casting
-- ON movie.id = casting.movieid
-- WHERE movie.yr = 1978
-- GROUP BY movie.id
-- ORDER BY actors DESC

-- # 16. List all the people who have worked with 'Art Garfunkel'.
SELECT a.name
Expand All @@ -143,4 +152,15 @@ SELECT a.name
JOIN casting
ON casting.actorid = actor.id
WHERE actor.name != 'Art Garfunkel') as a
ON m.id = a.movieid;
ON m.id = a.movieid;
-- # Another solution.
SELECT actor.name
FROM actor
JOIN casting
ON actor.id = casting.actorid
WHERE casting.movieid in (SELECT casting.movieid
FROM actor
JOIN casting
ON actor.id = casting.actorid
WHERE actor.name='Art Garfunkel')
AND actor.name != 'Art Garfunkel';