1

I am trying to query a table with WHERE IN condition using mysql-connector-python like this:

ids = (12, 31)
cursor.execute("SELECT object_name FROM object_table WHERE object_id IN %s", ids)

And I get the following error:

mysql.connector.errors.ProgrammingError: Not all parameters were used in the SQL statement

How can I get it working?

3 Answers 3

1

You should add "" in ids to be a String and also ',' should be replaced with '%'

E.g.

ids = "(12, 31)"
cursor.execute("SELECT object_name FROM object_table WHERE object_id IN %s" % ids)
Sign up to request clarification or add additional context in comments.

Comments

0

A query should be in the string format so you need to wrap your variable ids = (12, 31) into a string like ids = "(12, 31)" and also don't forget the add % instead of , as you're passing some value.

ids = "(12, 31)"
cursor.execute("SELECT object_name FROM object_table WHERE object_id IN %s" % ids)

Comments

0

old answer but might be helpful for someone

this is what I did and it might be helpful here if ids is a list.

query = "UPDATE tableName SET lspaasStatus = 1 WHERE CompletedQuizId IN " + "("+str(updatedQuizids)[1:-1]+")"
mycursor.execute(query)

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.