在SQL查询中的”JOIN”。

huangapple go评论97阅读模式
英文:

JOIN in SQL QUERY

问题

MYSQL返回错误**语法错误:预期输入结束,但得到了“=”在[9:66]**在以下INNER JOIN查询结果中:

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

可以有人帮忙理解错误是什么吗?

我已经尝试多次以不同的方式编写查询,但它不起作用。

英文:

MYSQL is returning error Syntax error: Expected end of input but got "=" at [9:66]
in result if below INNER JOIN Query:

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

Can someone please help to understand what is the error?

I have tried writing the query differently many times but it dosent work.

答案1

得分: 1

你有两个拼写错误,一个在SELECT语句中,一个在ON语句中,你使用了逗号 , 而不是点号 .。另外,考虑为表使用别名以提高可读性。

SELECT
  EMP.name,
  EMP.role,
  DEP.department_id
FROM `spherical-realm-388112.Customer_Data.Employees` AS EMP
JOIN `spherical-realm-388112.Customer_Data.departments` AS DEP
  ON EMP.department_id = DEP.department_id
英文:

You have two typos, one in the select, one in the ON statement, where you used a , instead of a .. Also consider using aliases for the tables for readability.

SELECT
  EMP.name,
  EMP.role,
  DEP.department_id
FROM `spherical-realm-388112.Customer_Data.Employees` AS EMP
JOIN `spherical-realm-388112.Customer_Data.departments` AS DEP
  ON EMP.department_id = DEP.department_id

huangapple
  • 本文由 发表于 2023年6月8日 19:38:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76431476.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定