1.

What are the differences between IN and BETWEEN operators?

Answer»

BETWEEN operator: In Python, BETWEEN operator is used in order to TEST whether the provided expression lies between a defined range of values or not. While testing, the range is inclusive. These values can be of any TYPE like date, NUMBER or text. We can use this BETWEEN operator with SELECT, INSERT, DELETE, and UPDATE statements. The syntax to apply this operator is as below.

SELECT column_name(s) FROM table_name WHERE column_name BETWEEN value1 AND value2;

Output: It will return all the values from above column_name which lies between value1 and value2 including these 2 values also.

IN operator: In Python, IN operator is used to check whether an expression matches with some of values that has been specified in a list containing values. It can be used in order to eliminate the use of multiple OR conditions. We can also use NOT IN operator which functions EXACTLY opposite to the IN operator to exclude certain rows from the output list. We can use this IN operator or NOT IN operator with SELECT, INSERT, DELETE, and UPDATE statements. The syntax to apply this operator is as below.

IN: SELECT column_name(s)       FROM table_name       WHERE column_name IN (list_of_values);

Output: It will return all the values from above column_name which matches with the specified “list_of_values”

NOT IN: SELECT column_name(s)               FROM table_name              WHERE column_name NOT IN (list_of_values);

Output: It will return all the values from above column_name excluding the specified “list_of_values”



Discussion

No Comment Found