Python MySQL – BETWEEN and IN Operator
In this article, we are going to see the database operations BETWEEN and IN operators in MySQL using Python.
Both of these operators are used with the WHERE query to check if an expression is within a range or in a list of values in SQL. We are going to use the below table to perform various operations:
The SQL BETWEEN condition is used to test if an expression is within a range of values (inclusive). The values include text, date, or numbers.
- It can be used along with the SELECT, INSERT, UPDATE, or DELETE statement.
- The SQL BETWEEN Condition will return the records where the expression is within the range of value1 and value2.
SELECT column1,column2,….,column n
WHERE column_name BETWEEN value1 AND value2;
Example 1: Python MySQL program to demonstrate the use of BETWEEN operator.
The SQL IN operator allows you to easily test if the expression matches any value in the list of values. It is used to remove the need for multiple OR conditions in SELECT, INSERT, UPDATE or DELETE. You can also use NOT IN to exclude the rows in your list.
SELECT column1,column2,…,column n
WHERE column IN (val1,val2,…,valn);
Example 2: Python MySQL program to demonstrate the use of IN operator.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course