【问题标题】:how to debug mysql join error如何调试mysql连接错误
【发布时间】:2016-02-16 10:59:18
【问题描述】:

执行代码中提到的 SQL 语句时出现以下错误。如何调试这个问题?

ERROR 1064 (42000):您的 SQL 语法有错误;检查 与您的 MySQL 服务器版本相对应的手册 'UNION select from employee right outer join附近使用的语法 第 1 行的employee.dept_no ' 所在部门

代码

select * 
from employee 
full outer JOIN department 
on employee.dept_no is null or department.dept_no is null; 

select * 
from employee 
left outer join department 
UNION 
select from employee 
right outer join department 
where employee.dept_no <> department.dept_no;

【问题讨论】:

  • 语法错误很简单,但您的查询看起来很可疑。你到底想达到什么目的?显示表定义、一些示例数据和预期输出。

标签: mysql database join


【解决方案1】:

您在 UNION 的第二次选择中错过了列名 (*)。

原来是UNION select from employee 改为 => UNION select * from employee

正如@Drew 所说,错过了ON 子句和OUTER JOINS

这个查询可以正常工作。

select * 
from employee
 left outer join  department  ON --Some condition here--
 UNION
 select * 
from employee
 right outer join department ON --Some condition here--
WHERE employee.dept_no <> department.dept_no;

希望这会有所帮助。

【讨论】:

  • 是的..我自己错过了ON子句..对吗?
  • 你明白了。如果没有架构,我们就不走运
猜你喜欢
  • 2018-05-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-05
  • 2020-03-26
  • 2017-07-10
  • 1970-01-01
  • 2012-06-22
相关资源
最近更新 更多