Where is used to select data on condition. Now, we will select a record with name Siddharth.
SELECT column_name FROM table_name WHERE condition statement will be used to retrieve the data on some condition.
import mysql.connector as mysql
db = mysql.connect(
host="localhost",
user="root",
passwd="[email protected]",
database="realprogrammer"
)
cursor = db.cursor()
## defining the Query
query = "SELECT * FROM user WHERE name = 'Siddharth'"
## getting records from the table
cursor.execute(query)
## fetching all records from the 'cursor' object
records = cursor.fetchall()
## Showing the data
for record in records:
print(record)