You can download this code by clicking the button below.
This code is now available for download.
This function uses the mysql-connector-python library to execute a SQL query with a cursor object and randomly returns one row from the query results.
Technology Stack : mysql-connector-python, cursor, execute, fetchone
Code Type : Database query
Code Difficulty : Intermediate
def fetch_random_data(cursor, query):
cursor.execute(query)
random_row = cursor.fetchone()
return random_row