Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to fix beginner SQL INNER JOIN query error

I tried to replicate an exercise from an online course in my bigquery sandbox, but it gives me an error. Can someone explain to me what is the error meaning and possibly how to fix this query?

schema table employees: nome (string), id_departmento (integer), cargo (string)

schema table departments: nome (string), id_departmento (integer)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  SELECT
     employees.nome AS employees_name,
     employees.cargo AS employees_role,
     departments.nome AS departments_name
  FROM
    `primeiro-projeto-da.employee_data.employees`
  INNER JOIN
    employee_data.departments 
  ON
    employees.id_departmento = departments.id_departmento

It returns the following error –

Unrecognized name: employees at [10:3]

I checked the names and values but I don’t understand where is the mistake, as the syntaxe seems good to me.
I was expecting a table with the name of the employees, their role and the corresponding department.

Notice that there are small name differences due to translation of table names in the picture I provide, but as far as I can tell not significant or relevant to the exercise itself.

Thank you for your trouble.

>Solution :

This may be due to the absence of aliases for the "employees" and "departments" tables. You can try modifying your query by adding aliases for the tables as follows:

SELECT
  employees.nome AS employees_name,
  employees.cargo AS employees_role,
  departments.nome AS departments_name 
FROM
  `primeiro-projeto-da.employee_data.employees` AS employees
INNER JOIN
  employee_data.departments AS departments
ON
  employees.id_departmento = departments.id_departmento;

If it’s not because of aliasing, make sure the tables are linked by a foreign key.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading