考虑以下SQL:
SELECT mov
FROM movie
WHERE mov IN
(
SELECT mov
FROM movie_star
GROUP BY(mov)
HAVING count(star) > 6
)
INNER JOIN movie_star
ON movie_star.mov = movie.mov;
执行此查询时出现以下错误:
.ERROR 1064(42000):您的SQL语法有错误;检查 手册,对应右边的MySQL服务器版本 在movie_star.mov =上使用'inner join movie_star'附近的语法 movie.mov'在第3行
答案 0 :(得分:5)
JOIN
必须在WHERE
子句之前。
SELECT movie.mov
FROM movie
INNER JOIN movie_star ON movie_star.mov = movie.mov
WHERE mov IN (SELECT mov FROM movie_star GROUP BY mov HAVING COUNT(star) > 6);
答案 1 :(得分:3)
这是相同的查询清理了一下:
select mov
from movie
where
mov in (select mov from movie_star group by(mov) having count(star) > 6)
inner join movie_star on movie_star.mov = movie.mov
您遇到语法错误,因为在inner join
子句后面会出现where
,而它应该出现在from
子句后面。
请改为尝试:
select mov
from movie
inner join movie_star on movie_star.mov = movie.mov
group by mov
having count(*) > 6
答案 2 :(得分:1)
你的内部联接在错误的地方。当您只选择movie.mov
列并且IN子句已经保证movie_star
中存在匹配的行时,我不确定是否需要内连接。
select mov
from movie
inner join movie_star
on movie_star.mov = movie.mov
where mov in (select mov
from movie_star
group by(mov)
having count(star)>6);
答案 3 :(得分:1)
你必须加入才能使用where子句:
select mov from movie
inner join movie_star on movie_star.mov = movie.mov
where mov in
(select mov from movie_star group by(mov) having count(star)>6)