![]() |
VOOZH | about |
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:
👁 ImageThe SQL BETWEEN condition is used to test if an expression is within a range of values (inclusive). The values include text, date, or numbers.
Syntax:
SELECT column1,column2,....,column n
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
Example 1: Python MySQL program to demonstrate the use of BETWEEN operator.
Output:
👁 ImageThe 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.
Syntax:
SELECT column1,column2,...,column n
FROM tablename
WHERE column IN (val1,val2,...,valn);
Example 2: Python MySQL program to demonstrate the use of IN operator.