this is database structure :http://sqlzoo.net/movie.htm MY problem is this "List the films where 'Harrison Ford' has appeared - but not in the star role. [Note: the ord field of casting gives the position of the actor. If ord=1 then this actor is in the starring role]" I wrote this query "SELECT title FROM movie inner join casting on (casting.movieid = movie.id) inner join actor (actor.id =casting.actorid) where actor.name = "Harrison Ford" and ord = 2;" BUT IT IS WRONG. CAN YOU TELL ME WHATS WRONG
SELECT title FROM movie WHERE casting.movieid = movie.id AND actor.id = casting.actorid AND actor.name = "Harrison Ford" AND casting.ord = 2;
If the above doesn't work, try: SELECT title FROM movie WHERE casting.movieid = movie.id AND actor.id = casting.actorid AND actor.name LIKE '%Harrison Ford%' AND casting.ord = 2;
This query should work for you. SELECT title FROM movie WHERE actor.name = 'Harrison Ford' AND casting.actorid = actor.id AND casting.ord > 1 AND movie.id = casting.movieid
Here's my attempt: SELECT m.title FROM movie m ,actor a ,casting c WHERE m.id = c.movieid AND a.id = c.actorid AND a.name = 'Harrison Ford' AND c.ord > 1 Code (markup):