mysql

In Operator MySQL

Using IN operator you can check whether column values exist in a list of values or in records of a subquery.

-- Match with list values
SELECT 
    first_name, 
    last_name,
    city
FROM
    Students
WHERE
    city IN ('Delhi' , 'Newyork');


--Match with subquery records
SELECT    
	first_name, 
    last_name,
    city
FROM    
	Students
WHERE city IN
(
    SELECT 
        city
    FROM 
        city_list
);

You can also use the NOT IN operator to select records that do not exist in a set of values. The example MySQL query can be written as below.

SELECT 
    first_name, 
    last_name,
    city
FROM
    Students
WHERE
    city NOT IN ('Delhi' , 'Newyork');
Was this helpful?