How to write a mysql prepared SELECT statement in python 3 using LIMIT?

Viewed 135
idValue = 100
limitValue = 10000
query = "SELECT count(*) as count FROM oneTable WHERE id = (%s) LIMIT (%s)";
cursor.execute(query, (idValue, limitValue ))

This doesn't seem to be working. It fetches only 1 record corresponding to the id.

2 Answers

I think that this should work as you want. If you print result, you can see result of your query.

idValue = 100
limitValue = 10000
query = "SELECT count(*) as count FROM oneTable WHERE id = {0} limit {1}".format(idValue,limitValue)
cursor.execute(query)
result = cursor.fetchall()

The original query in the question does work. There was some other bug in my code and hence it ceased to work then. Thanks @Baran

Related