Search code snippets, questions, articles...

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');

Search Index Data (The code snippet can also be found with below search text)

Select records if exists in a set of values MySQL
Was this helpful?
0 Comments
Programming Feeds
Learn something new everyday on Devsheet