You can download this code by clicking the button below.
This code is now available for download.
Selects 5 random users from a database.
Technology Stack : Python, Pytest, SQLite3
Code Type : Database query
Code Difficulty : Intermediate
def random_select_users_from_database(db_connection):
cursor = db_connection.cursor()
cursor.execute("SELECT * FROM users ORDER BY RAND() LIMIT 5")
users = cursor.fetchall()
cursor.close()
return users