首页 > 解决方案 > mysql通过交叉连接加入三个表错误

问题描述

我想获得一些不在用户名评级表中的详细信息,我进行了交叉连接查询。但它向我显示语法错误

SELECT applications.reference as "User id", applications.id
FROM applications
cross join ratings where (applications.id) NOT IN ( SELECT ratings.application_id FROM ratings )
INNER JOIN ratings ON users.id=ratings.user_id

错误显示

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'INNER JOIN ratings ON users.id=ratings.user_id LIMIT 0, 25' at line 2

我想在用户表中的用户名不在评级表中的应用程序中获取用户详细信息。我怎样才能解决这个问题?

标签: mysqlsql

解决方案


我认为您需要这样的查询:

SELECT a.reference as "User id", a.id
  FROM applications a
 CROSS JOIN ratings r
 INNER JOIN users u ON u.id = r.user_id 
 WHERE a.id != r.application_id;

推荐阅读