Sql help

Discussion in 'MySQL' started by phpsolution, Apr 25, 2012.

  1. #1
    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
     
    phpsolution, Apr 25, 2012 IP
  2. lektrikpuke

    lektrikpuke Well-Known Member

    Messages:
    297
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    113
    #2
    SELECT title FROM movie WHERE casting.movieid = movie.id AND actor.id = casting.actorid AND actor.name = "Harrison Ford" AND casting.ord = 2;
     
    lektrikpuke, May 6, 2012 IP
  3. lektrikpuke

    lektrikpuke Well-Known Member

    Messages:
    297
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    113
    #3
    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;
     
    lektrikpuke, May 6, 2012 IP
  4. DennisRitchieCollective

    DennisRitchieCollective Peon

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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
     
  5. DaySeven

    DaySeven Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    2
    Trophy Points:
    0
    #5
    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):
     
    DaySeven, May 22, 2012 IP