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.
SELECT column1, column2, …. cloumnN 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:
Where Clause In Python
Steps to use where clause in Python is:
- First form a connection between MySQL and Python program. It is done by importing mysql.connector package and using
mysql.connector.connect()method, for passing the user name, password, host (optional default: localhost) and, database (optional) as parameters to it.
- Now, create a cursor object on the connection object created above by using
cursor()method. A database cursor is a control structure that enables traversal over the records in a database.
- Then, execute the where clause statement by passing it through
- Python MySQL - Limit Clause
- Python MySQL - Order By Clause
- Connect MySQL database using MySQL-Connector Python
- Python MySQL - Join
- MySQL-Connector-Python module in Python
- Python: MySQL Create Table
- Python MySQL - Insert into Table
- Python MySQL - Delete Query
- Python MySQL - Update Query
- Python MySQL - Drop Table
- Python MySQL - Select Query
- Python MySQL - Create Database
- How to install MySQL connector package in Python?
- Create MySQL Database Login Page in Python using Tkinter
- Reusable piece of python functionality for wrapping arbitrary blocks of code : Python Context Managers
- Python - Read blob object in python using wand library
- Python | Convert list to Python array
- Python | PRAW - Python Reddit API Wrapper
- Python | Merge Python key values to list
- Python | Index of Non-Zero elements in Python list
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Akanksha_Rai