Error: "Unrecognized name: employees at [9:8]"
]When using table alias, you may encounter the "Unrecognized name: employees at [9:8]" error. Let's analyze the reasons and provide the right solution.
Error analysis:
In the provided SQL query:
SELECT
employees.name AS employee_name,
employees.role AS employee_role,
departments.name AS department_name
FROM
`strange-calling-318804.employee_data.Employees`
JOIN
`strange-calling-318804.employee_data.departments`
ON employees.department_id = departments.department_id
employees
and departments
alias are used in the ON
clause:
ON employees.department_id = departments.department_id
However, the Employees
and departments
tables do not have explicitly defined alias in the FROM
clause. This leads to an error because BigQuery requires that they must be defined before using aliases.
Solution:
To resolve this error, they must be defined before using the alias:
SELECT
employees.name AS employee_name,
employees.role AS employee_role,
departments.name AS department_name
FROM
`strange-calling-318804.employee_data.Employees` AS employees
JOIN
`strange-calling-318804.employee_data.departments` AS departments
ON employees.department_id = departments.department_id
By adding aliases AS employees
and AS departments
] after the full table reference, the query now correctly recognizes the table and executes without errors.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3