Umair Maqsood
Umair Maqsood

Reputation: 11

Nobe at SQL scripting. Please haalp

I am trying to access my table in SQL database. However, I am getting an unusual error. Can someone please help me I am very new at this.

import sqlite3
import pandas as pd
com = sqlite3.connect('Reporting.db')

Note: Panda dataframe is already defined above that's why I am not including this over here.

df.to_sql('tblReporting', com, index=False, if_exists='replace')
print('tblReporting loaded \n')```   

%load_ext sql
%sql sqlite:///Reporting.db
%%sql
SELECT *
FROM tblReporting

This is the error I am getting

SELECT *
^ SyntaxError: invalid syntax

Note #2: I am using Anaconda Navigator for writing scripts

Upvotes: 0

Views: 38

Answers (1)

Umair Maqsood
Umair Maqsood

Reputation: 11

Solved it!! that's my Syntax

 import sqlite3    
 import pandas as pd  
 com = sqlite3.connect('Reporting.db')  
 df.to_sql('tblReporting', com, index=False, if_exists='replace')  
 print('tblReporting loaded \n')  
 org_query = '''SELECT * FROM tblReporting'''    
 df = pd.read_sql_query(org_query, com)  
 df.head()

Note: added ''' before and after my org_query helped me resolved this

Upvotes: 0

Related Questions