Skip to content Skip to sidebar Skip to footer

How To Use Fetchmany() To Fetch The Next Set Of Results?

I want to fetch a hundred of results from MySql using fetchmany(100) in Python. But I am wondering if there's a way to fetch the next set of results in case what I want is not avai

Solution 1:

Instead of using fetchmany(), you can use fetchall(), but include in your select query the following:

SELECT*from data limit 00,30; 

The 00 indicates the position The 30 indicates the number of the rows you want to output as the result.

Hence, you can make introduce the position using a variable that increases every time you want to fetch more results.

E.g

position= 00while True:
    nothing = input("Do you want more input?")

    data = c.execute("SELECT * from data limit {}, 50".format(amount))
    data = c.fetchall()
    position += 50

Post a Comment for "How To Use Fetchmany() To Fetch The Next Set Of Results?"