Can anyone explain why the following code makes an error? I want to merge 2 Tables from SQL Database...
sql_query = '''
SELECT departments.dept_name, dept_emp.emp_no, dept_emp.dept_no, dept_emp.to_date,
FROM departments
JOIN dept_emp
ON departments.dept_no = dept_emp.dept_no
WHERE dept_emp.to_date == "9999-01-01"
LIMIT 20
'''
df_dept_emp_departments_now = pd.read_sql(sql_query, connection)
OperationalError: (sqlite3.OperationalError) near "FROM": syntax error
[SQL:
SELECT departments.dept_name, dept_emp.emp_no, dept_emp.dept_no, dept_emp.to_date,
FROM departments
JOIN dept_emp
ON departments.dept_no = dept_emp.dept_no
WHERE dept_emp.to_date == "9999-01-01"
LIMIT 20
]
(Background on this error at: http://sqlalche.me/e/e3q8)
Can anyone debug the code?
CodePudding user response:
Remove the comma just before FROM keyword
CodePudding user response:
The error is due to , before FROM clause
SELECT departments.dept_name, dept_emp.emp_no, dept_emp.dept_no, dept_emp.to_date FROM departments JOIN dept_emp ON departments.dept_no = dept_emp.dept_no WHERE dept_emp.to_date == "9999-01-01" LIMIT 20