mysql - 几乎没有 JOIN 的 SQL

标签 mysql sql compiler-errors

关闭。这个问题需要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/

相关文章:

sql - 找出 SQL Server 上的查询中获取了哪些锁?

sql - 获取该月的 2 位数字

mysql - 如何编写 "balanced"sql select 查询

mysql - 在我的 INNER JOIN 中使用 OR 子句

mysql - 创建 Proc 在 END 语句上返回 1064/42000 错误

mysql - 无法启动服务 MySQL.error 0

sql - LIKE '%' 的全文搜索等效项是什么?

c++ - 工厂方法和循环依赖

qt - 编译Qt项目时出现 “g++: CreateProcess: No such file or directory”错误

c# - 错误CS0201-无法理解我的代码出了什么问题