Slide 11.16: The AND and OR keywords
Slide 11.18: The BETWEEN operator
Home

The IN Operator


The IN operator may be used if you know the exact value you want to return for at least one of the columns.

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

LastName FirstName Address City
Hansen Ola Timoteivn 10 Sandnes
Nordmann Anna Neset 18 Sandnes
Pettersen Kari Storgt 20 Stavanger
Svendson Tove Borgvn 23 Sandnes

To display the persons with LastName equal to “Hansen” or “Pettersen”, use the following SQL:

 SQL> select  *  from  Persons
   2    where  LastName  in  ('Hansen', 'Pettersen');

The following results are displayed:

LastName FirstName Address City
Hansen Ola Timoteivn 10 Sandnes
Pettersen Kari Storgt 20 Stavanger



The following is an SQL test area from w3schools.com where the Customers table may be created by the following command:
   SQL> create table  Customers (
     2    CustomerID   varchar(16),
     3    CompanyName  varchar(32), 
     4    ContactName  varchar(32),
     5    Address      varchar(64),
     6    City         varchar(32), 
     7    PostalCode   varchar(16), 
     8    Country      varchar(32) );
Note that the Customers table is for read only.


      SQL Execution Results