Search code examples
sqlmysqlsyntax-errorinner-join

JOIN in SQL QUERY


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.


Solution

  • 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