Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

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!

share|improve this question
    
I think we need your runstr – KRONWALLED Jul 12 at 13:56
    
runstr is a string of numbers separated by comma: 'runstr = 60092,60093,60094' – id5h Jul 12 at 14:00
up vote 1 down vote accepted

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.

share|improve this answer
    
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 – id5h Jul 12 at 14:11
    
Edited my answer with a link that should resolve your problem. – Nee Jul 12 at 14:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.