Hostgre


HomeReferenceSQLSQL IN Operator

SQL IN Operator

The IN operator allows you to specify multiple values in a WHERE clause. The IN operator is a shorthand for multiple OR conditions.

IN Syntax

SELECT column_name(s) FROM table_name WHERE column_name IN (value3, value4, ...);
or:
SELECT column_name(s) FROM table_name WHERE column_name IN (SELECT STATEMENT);

Demonstration

Here is a selection from the "Customers" table in the sample database:
CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry
1Antoniev AzarovAntoniev AzarovSvaruska 876Kiev00234Ukraine
2Ana SarinaAna Sarina3th Avenue 1111New York01028US
3Juan Moreno ValdézJuan Moreno4th Avenue 2370New York01025US
4TBergerThomas Berger500 Baker Sq.LondonWA3 5DPUK
5LcunhaLuís CunhaAv. Esplanada 850Brasília00232876Brazil


IN Operator Examples

The following SQL statement selects all the customers that are located in "Ukraine", "Brazil" and "US":

Example

SELECT * FROM Customers WHERE Country IN ('Ukraine', 'Brazil', 'US');
The following SQL statement selects all the customers that are NOT located in "Ukraine", "Brazil" or "US":

Example

SELECT * FROM Customers WHERE Country NOT IN ('Ukraine', 'Brazil', 'US');
The following SQL statement selects all the customers that are from the same countries as the suppliers:

Example

SELECT * FROM Customers WHERE Country IN (SELECT Country FROM Suppliers);