MySQLdb Fetching results

(Sponsors) Get started learning Python with DataCamp's free Intro to Python tutorial. Learn Data Science by completing interactive coding challenges and watching videos by expert instructors. Start Now!

In the previous post we have seen how to execute sql queries using execute()  method. execute()  method returns affected rows, it doesn’t return the result. To fetch result we use the fetchall()  method of the cursor object

Syntax: cursor.fetchall()

On success it returns tuple of rows where each row is a tuple.

above code will print all the rows in the city table.

You can also use for loop to iterate over the results.

Some more examples.

Example 1:

Example 2:


Other Tutorials (Sponsors)

This site generously supported by DataCamp. DataCamp offers online interactive Python Tutorials for Data Science. Join over a million other learners and get started learning Python for data science today!

2 thoughts on “MySQLdb Fetching results

  1. Ken Clement

    Syntax: cursor.fethcall() should instead read: Syntax: cursor.fetchall()

    There is a letter transposition in fetchall – should be ‘ch’ instead of ‘hc’


Leave a Reply

Your email address will not be published. Required fields are marked *