0

I'm writing a python script that connects to a MariaDB server (V 10.1.12) and saves to file the results of some queries. However, when sending the following query:

sql =   'SELECT * FROM Monitor_Run_Tracking WHERE Entry IN (SELECT MAX(Entry) ' \
        'FROM Monitor_Run_Tracking WHERE Run in ({0}) ' \
        "AND WhenEntered<'{1}' GROUP BY Run)".format( runstr, quality_date )

followed by cursor.execute( sql ), I get the following error:

File "build/bdist.linux-x86_64/egg/MySQLdb/cursors.py", line 174, in execute
File "build/bdist.linux-x86_64/egg/MySQLdb/connections.py", line 36, in defaulterrorhandler _mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') AND WhenEntered<'2020-01-01' GROUP BY Run)' at line 1")

Could someone explain to me what the mistake is?

Thanks!

2
  • I think we need your runstr Commented Jul 12, 2016 at 13:56
  • runstr is a string of numbers separated by comma: 'runstr = 60092,60093,60094' Commented Jul 12, 2016 at 14:00

1 Answer 1

1

You didn't close the parenthesis around the nested select. It should be

SELECT * FROM Monitor_Run_Tracking WHERE Entry IN (
        SELECT MAX(Entry)
        FROM Monitor_Run_Tracking WHERE Run in ({0})
        AND WhenEntered<'{1}')
GROUP BY Run

or

SELECT * FROM Monitor_Run_Tracking WHERE Entry IN (
        SELECT MAX(Entry)
        FROM Monitor_Run_Tracking WHERE Run in ({0})
        AND WhenEntered<'{1}'
        GROUP BY Run)

EDIT: For the other problem, you're grouping by a field that you're not selecting. Check out this question for help.

Sign up to request clarification or add additional context in comments.

2 Comments

Sorry, that mistake was a copy and paste from a one of my debugging iterations. It was originally closed properly. I edited the question appropriately now. Thanks
Edited my answer with a link that should resolve your problem.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.