Last Updated : 28 Apr, 2025
Where clause is used in MySQL database to filter the data as per the condition required. You can fetch, delete or update a particular set of data in MySQL database by using where clause.
Syntax
SELECT column1, column2, .... columnN FROM [TABLE NAME] WHERE [CONDITION];
The above syntax is used for displaying a certain set of data following the condition.
Example: Consider the following database named college and having a table name as a student.
Schema of the database:
Database:
Steps to use where clause in Python is:
import mysql.connector
#Establishing connection
conn = mysql.connector.connect(user='your_username',
host='localhost',
password ='your_password',
database='College')
# Creating a cursor object using
# the cursor() method
mycursor = conn.cursor();
# SQL Query
sql = "select * from Student where Roll_no >= 3;"
# Executing query
mycursor.execute(sql)
myresult = mycursor.fetchall()
for x in myresult:
print(x)
# Closing the connection
conn.close()
OUTPUT:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4