gpk27
gpk27

Reputation: 829

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

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.

Upvotes: 3

Views: 159

Answers (2)

gpk27
gpk27

Reputation: 829

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

Upvotes: 1

Baran Barakcin
Baran Barakcin

Reputation: 41

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()

Upvotes: 1

Related Questions