-2

我正在尝试获取詹姆斯卡梅隆导演的电影

select mov_title 
from movie 
inner join movie_direction on movie.mov_id = movie_direction.dir_id
inner join movie_direction on director 
where director.fname='james' and director.lname='Cameron';
4

2 回答 2

0

您不能在同一查询中引用 movie_direction 表两次,除非在至少一个连接中为其指定别名。在您的一个连接或两者中提供别名。

IE

inner join movie_direction md1 on {your condition}
inner join movie_direction md2 on {your condition}

您的查询应该是这样的

SELECT 
 *
 FROM (movie INNER JOIN movie_direction ON movie.mov_id = 
 movie_direction.mov_id) INNER JOIN director ON movie_direction.dir_id = 
 director.dir_id
 WHERE    director.dir_fname='james' and director.dir_lname='Cameron';
于 2018-04-24T10:14:28.823 回答
0

这应该有效:

SELECT 
    mov_title 
FROM 
    movie 
    INNER JOIN 
    movie_direction director
ON 
    movie.mov_id = director.mov_id 
WHERE 
    director.fname='james' 
AND 
    director.lname='Cameron');

您的查询中的错误是您将 mov_id 与 dir_id 联接,并且只需要一个联接。

于 2018-04-24T10:17:32.827 回答