SQL JOIN查询语法错误求助:MySQL报预期输入结束却得到'='
MySQL INNER JOIN语法错误排查与修正
你的查询语句存在两处语法错误,导致MySQL返回指定的语法错误提示:
错误点分析
- SELECT子句列引用错误:第二行的
spherical-realm-388112.Customer_Data.Employees,role 中,表名和列名之间误用了逗号(,),正确的关联符号应为点号(.),即spherical-realm-388112.Customer_Data.Employees.role。 - JOIN关联条件列引用错误:最后一行的
spherical-realm-388112.Customer_Data.departments,department_id 中,同样误用逗号替代了点号,正确写法为spherical-realm-388112.Customer_Data.departments.department_id。
修正后的查询语句
SELECT `spherical-realm-388112.Customer_Data.Employees`.name, `spherical-realm-388112.Customer_Data.Employees`.role, `spherical-realm-388112.Customer_Data.departments`.department_id FROM `spherical-realm-388112.Customer_Data.Employees` INNER JOIN `spherical-realm-388112.Customer_Data.departments` ON `spherical-realm-388112.Customer_Data.departments`.department_id = `spherical-realm-388112.Customer_Data.Employees`.department_id
如果想简化语句提升可读性,可以给表设置别名:
SELECT emp.name, emp.role, dept.department_id FROM `spherical-realm-388112.Customer_Data.Employees` emp INNER JOIN `spherical-realm-388112.Customer_Data.departments` dept ON dept.department_id = emp.department_id
内容的提问来源于stack exchange,提问作者Hina Saleem
相关产品推荐
相关产品推荐

