Learn From - Interactive SQL



SQL IN Operator


If a particular column has many different values and you need to extract records having only certain values. In the Where clause you provide a set of values that are present in the column and records containing these values are to be retrieved, you can use the IN operator for this condition.

SQL IN Operator Syntax


SELECT column_name1, column_name2 ...
FROM table_name
WHERE column_name IN (value1,value2,...)

Below is shown the "Customers" table:

CustomerID CustomerName EmailID Address City PostalCode Country
C001 Fredrick Johnson FJohnson@yahoo.com Berkeley Gardens 12 Brewery London WX1 6LT UK
C002 Mary Davidson Mary@gmail.com 35 King George Madrid 28023 Spain
C003 George Clooney George@hotmail.com Obere Str. 57 Berlin 12209 Germany
C004 David Louis David@mail.com 2743 Bering St. NewJersy 07019 USA
C005 Johnny Anderson Johnny@gmail.com 55 Grizzly Peak Rd. NewJersy 07019 USA
C006 Paul Henriot PaulHenriot@yahoo.com 59 rue de l'Abbaye Paris 51100 France
C007 Henry King Henry@mail.com 120 Hanover Sq. London WA1 1DP UK
C008 Robert John Robert@gmail.com 87 Polk St. Suite 5 San Francisco 94117 USA

SQL IN Operator Example


Type or Copy the SQL into the Text Editor, click the "View Result" button, to see the result.

To retrieve all the records from the Customers table with Country column names "UK" and "Germany"

SELECT * FROM Customers
WHERE Country IN ('UK','Germany');

To retrieve all the records from Customers table with City column names "Madrid", "Berlin" and "Paris"

SELECT * FROM Customers
WHERE City IN ('Madrid','Berlin','Paris');

SQL in Text Editor: