1

I'm using pandas to do some calculations with big data sets. I'm getting my data from a local sql-database. Now I want to select the last 100 rows of my sql table and load them into my dataframe.

df = pd.read_sql('SELECT TOP(100) * FROM testTable ORDER BY last_updated DESC', engine)

but it seems that my sql select command has the wrong syntax. Could you help me to correct my code?

1 Answers1

0

Try:-

df = pd.read_sql('SELECT TOP 100 * FROM testTable ORDER BY last_updated DESC', engine)

Brackets aren't used with TOP in some SQLs since every SQL (e.g POSTGRESQL, MYSQL, etc) has different syntax, this might be the problem perhaps

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103