gpt4 book ai didi

mysql - 几乎没有 JOIN 的 SQL

转载 作者:行者123 更新时间:2023-12-02 11:09:26 25 4
gpt4 key购买 nike

关闭。这个问题需要details or clarity .它目前不接受答案。












想改进这个问题?通过 editing this post 添加详细信息并澄清问题.

8年前关闭。




Improve this question




我想做一些内部连接但有错误 - 我做错了什么?

    SELECT genre.title title1, country.title title2 FROM  movie
-- genre
INNER JOIN genre ON genre.id = genreRelation.id_genre
INNER JOIN genreRelation ON movie.id = genreRelation.id_movie

-- country
INNER JOIN countryRelation ON movie.id = countryRelation.id_movie
INNER JOIN country ON country.id = countryRelation.id_country
WHERE movie.id = 1

最佳答案

您在连接中混合了未在 ON 子句中定义的表。

试试这个

 SELECT genre.title title1, country.title title2 FROM  movie
INNER JOIN countryRelation ON movie.id = countryRelation.id_movie

INNER JOIN genreRelation ON movie.id = genreRelation.id_movie
INNER JOIN genre ON genre.id = genreRelation.id_genre

LEFT JOIN country ON country.id = countryRelation.id_country
WHERE movie.id = 1
GROUP BY country.title

关于mysql - 几乎没有 JOIN 的 SQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22284979/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com