Home > Mobile >  Beginners SQL syntax error using INNERJOIN, error
Beginners SQL syntax error using INNERJOIN, error

Time:06-28

SELECT
   employees.name AS employees_name,
   employees.role AS employees_role,
   employee_data.departments.name AS department_name
FROM
  `mineral-oxide-354620.employee_data.employees` , 
INNERJOIN
   `mineral-oxide-354620.employee_data.departments ON

` mineral-oxide-354620.employee_data.employees.department_id = mineral-oxide- 354620.employee_departments_department_id

is the query and

Syntax error: Unclosed identifier literal at [8:4]

is the error.

Its an exercise using tables I made in BigQuery using a new project name of mineral-oxide-354620 and datasets I created first with the names employee_data.employees and employee_data.departments

I have signed up for other SQL classes to see if errors are addressed or not, as the course I am taking has nothing but FAQ and asking other students so if they have not encountered this exact error you waste time to get kinda sorta input with similar things and may eventually figure it out. I was hoping to find a better methodology when encountering seemingly simple syntax errors using BiqQuery.

The course gets a join of employee and department data from each table together, but I get the syntax error and can't get the query to run Thanks

CodePudding user response:

Did you put a closing backtick?

CodePudding user response:

Since you are including full database/owner/table as the context of the from/join, it would probably be better to simplify by applying ALIAS names to the tables. An alias is a shortened context to the table, but enough that you still know its origin. Because of the database having dashes in it makes sense to clarify with ticks around it.

SELECT
        e.name AS employees_name,
        e.role AS employees_role,
        d.name AS department_name
    FROM
        `mineral-oxide-354620.employee_data.employees` e 
            INNER JOIN `mineral-oxide-354620.employee_data.departments` d
                ON e.department_id = d.department_id

You also had a comma AFTER your employees table before the inner join which would have caused a failure to execute the query. also Inner join is TWO words, not a single. Notice by me using the alias "e" for employees and "d" for departments, the join ON command is easier to read the e.column = d.column

Hopefully enough to get you back on track.

  •  Tags:  
  • sql
  • Related