diff --git a/6_join.sql b/6_join.sql index 0ea19af..a2f7617 100644 --- a/6_join.sql +++ b/6_join.sql @@ -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 \ No newline at end of file +ORDER BY game.mdate, goal.matchid diff --git a/7_more_join_operations.sql b/7_more_join_operations.sql index 15d5953..6440b88 100644 --- a/7_more_join_operations.sql +++ b/7_more_join_operations.sql @@ -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 @@ -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; \ No newline at end of file + 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';