1
**When i am running below query**

from sqlalchemy import create_engine
import pymysql
import pandas as pd
import datetime
db_connection_str = 'mysql+pymysql://root:*****@localhost/northwind'
db_connection = create_engine(db_connection_str)
df = pd.read_sql('SELECT * FROM employees where BirthDate between '1948-12-08' and '1960-05-29'', con=db_connection)
df

**I am receiving below Error**

  File "", line 7
    df = pd.read_sql('SELECT * FROM employees where BirthDate between '1948-12-8' and '1960-5-29'', con=db_connection)
                                                                          ^
SyntaxError: invalid syntax

--------------------------------------------------------------------------------------------------

1 Answer 1

2

Use double quotes to enclose the sql statement since you use single quotes inside the statement for the dates:

df = pd.read_sql("SELECT * FROM employees where BirthDate between '1948-12-08' and '1960-05-29'", con=db_connection)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.