'How to solve an error with JOIN tables in SQL? [duplicate]
When I try to run the code below, I get the error:
Unrecognized name: employees at [7:1]
There are two tables in the database employee_data. One is called employees and the other departments.
SELECT
employees.name as employee_name,
employees.role as employee_role,
departments.name as department_name
FROM
`potent-electron-345605.employee_data.employees`
INNER JOIN
employee_data.departments ON employees.department_id = departments.department_id
I also tried the code below (using the database.table), but got the error
Unrecognized name: employee_data at [7:1]
SELECT
employees.name AS employee_name,
employees.role AS employee_role,
departments.name AS department_name
FROM
`potent-electron-345605.employee_data.employees`
INNER JOIN
employee_data.departments ON employee_data.employees.department_id = employee_data.departments.department_id
Solution 1:[1]
You have a trailing ` mark on line 7 that you should eliminate. Also, try using aliases:
SELECT
employees.name as employee_name,
employees.role as employee_role,
departments.name as department_name
FROM `potent-electron-345605.employee_data.employees` AS E
INNER JOIN employee_data.departments AS D
ON E.department_id = D.department_id
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Paul Neralich |
