Python MariaDB - Where Clause using PyMySQL Last Updated : 14 Oct, 2020 Comments Improve Suggest changes Like Article Like Report Where clause is used in MariaDB database to filter the data as per the condition required. You can fetch, delete or update a particular set of data in MariaDB database by using the where clause. Syntax : 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 1: Consider the following database named GFG and having a table name as a PRODUCT. Schema of the Table: Table data : Where Clause In Python : Steps to use where clause in Python is: First form a connection between MariaDB and Python program. It is done by importing pymysql package and using pymysql.connect() method, for passing the username, 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 the 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 the execute() method. Python3 import pymysql # Create a connection object # IP address of the MySQL database server Host = "localhost" # User name of the database server User = "user" # Password for the database user Password = "" database = "GFG" conn = pymysql.connect(host=Host, user=User, password=Password, database) # Create a cursor object cur = conn.cursor() query = f"SELECT price,PRODUCT_TYPE FROM PRODUCT WHERE price > 10000" cur.execute(query) rows = cur.fetchall() for row in rows : print(row) conn.close() Output : Example 2 : Python3 import pymysql # Create a connection object conn = pymysql.connect('localhost', 'user', 'password', 'database') # Create a cursor object cur = conn.cursor() query = f"SELECT * FROM PRODUCT WHERE PRODUCT_TYPE in ('Voice','DLC','CALL')" cur.execute(query) rows = cur.fetchall() for row in rows : print(row) conn.close() Output : Comment More infoAdvertise with us Next Article Python MariaDB - Where Clause using PyMySQL P pratapworkmail Follow Improve Article Tags : Python SQL Practice Tags : python Similar Reads Python MariaDB - Limit Clause using PyMySQL The Limit clause is used in SQL to control or limit the number of records in the result set returned from the query generated. By default, SQL gives out the required number of records starting from the top but it allows the use of the OFFSET keyword. OFFSET allows you to start from a custom row and 2 min read Python MariaDB - Order By Clause using PyMySQL A MySQL client library is employed when we have to use MySQL with other programming languages. The work of PyMySQL is to provide access to MySQL Driver to the required language. Thus, it generates a connection between the programming language and the MySQL Server. OrderBy Clause The OrderBy is used 2 min read Python MySQL - Where Clause 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 2 min read Python MariaDB - Delete Query using PyMySQL DELETE is an SQL query, that is used to delete one or more entries from a table with a given condition. To connect with MariaDB database server with Python, we need to import pymysql client. After connecting with the database in MySQL we can create tables in it and can manipulate them. Syntax: DELET 2 min read Create Database in MariaDB using PyMySQL in Python MariaDB is an open source Database Management System and its predecessor to MySQL. The pymysql client can be used to interact with MariaDB similar to that of MySQL using Python. In this article we will look into the process of creating a database using pymysql. To create a database use the below syn 2 min read Like