Python Fetchone Method
The fetchone() method is used to fetch only one row from the table. The fetchone() method returns the next row of the result-set.
Fetchone() Method
In the following example, we will connect to mysql database and fetch only one row which is next row of the result-set
Copied
import mysql.connector
myconn = mysql.connector.connect(host = "localhost", user = "root",password = "naveen",database = "PythonDB")
cur = myconn.cursor()
try:
cur.execute("select name, id, salary from Employee")
result = cur.fetchone()
print(result)
except:
myconn.rollback()
myconn.close()