IN & NOT IN OPERATOR in MySQL|| MySQL Tutorial|| Code With Neha

Опубликовано: 21 Март 2025
на канале: Code With Neha
321
64

TODAY IN MY MYSQL SERIES I am going toDISCUSS ABOUT IN OPERATOR

So without any further delay let's get started

The MySQL IN Operator

The IN operator allows you to specify multiple values in a WHERE clause.



It is a logical operator that allows us to check whether the values in a database are present in a list of values specified in the SQL statement.

The IN operator is a shorthand for multiple OR conditions.

It can be used with any data type in SQL. It is used to filter data from a database table based on specified values. It returns all rows in which the specified column value matches any one of the values in the list.



IN Syntax

SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1, value2, ...);

or:

SELECT column_name(s)
FROM table_name
WHERE column_name IN (SELECT STATEMENT);


Let's apply this with some examples

Today I am using CUSTOMERS1 table under orders_infotech database

query, retrieve the records with the names ‘Khilan’, ‘Hardik’, ‘Suresh’, from the CUSTOMERS table −

SELECT * FROM CUSTOMERS1 WHERE NAME IN ('Khilan', 'Hardik', 'Suresh');

Run the query to view the result

MySQL NOT IN operator

To negate a condition, we use the NOT operator. The MySQL IN operator can be used in combination with the NOT operator to exclude specific values in a WHERE clause.


basic syntax of NOT IN operator −

WHERE column_name NOT IN (value1, value2,...);


Query to display all the records from the CUSTOMERS table, where the AGE is NOT equal to '25', '23' and '22' −

SELECT * FROM CUSTOMERS1 WHERE AGE NOT IN (25, 23, 22);


Run the query to view the result


The IN Operator in UPDATE statement

The MySQL UPDATE statement is used to modify existing data in a database table. So, we can also use the IN operator in an UPDATE statement (as a filter) to update existing rows.

For example:-

Query to update the records of the customers with age ‘25’ or ‘27’ by setting their value to ‘30’ −

UPDATE CUSTOMERS1 SET AGE = 30 WHERE AGE IN (25, 27);


Run the query to view the result

that's all for today Hope you all will get some help from this video
If it's so then don't forget to subscribe my channel Code with Neha and press the Bell Icon for Regular Updates
See you in the next video till then Stay Safe Stay Happy

#sqlnotinoperator
#mysqlnotinoperator
#MySQLINOperator
#mysql
#mysqlInoperator
#sqlinoperator
#sqlwhereinoperatortutorial
#mysqltutorial
#mysqldatabase
#mysqlcourse
#mysqltutorialforbeginners
#learnmysql
#WHEREclause
#MySQLIN
#multiplevalueswithWHEREclause
#MySQLTutorial
#mysqltutorialforbeginners
#mysql
#mysqldb
#mysqltutorials
#mysqltutorialforbeginners
#mysqlupdatecommand
#sqlupdatecommand
#mysqldatabase
#mysqlcourse
#mysqldatabasetutorial
#mysqlcrashcourse
#mysqltutorialforbeginners
#learnmysql
#learnsql
#SqlDMLcommands
#createinsertupdateinsql
#sqlupdatequery
#sqlcommands
#sqlqueries
#structuredquerylanguage
#sqlinterviewquestions
#sqlbasics
#sqlforbeginners