The IN operator allows you to specify multiple values in a WHERE clause.This is one of the comparison keywords available in sql which
are used to enhance the search capabilities of a sql query.
Syntax:
SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1,value2,...);
Example:
Here is the EMPLOYEE1 table:
ID
|
NAME
|
START_DATE
|
END_DATE
|
SALARY
|
CITY
|
1
|
A
|
01/01/2016 00:00:00
|
01/06/2016 00:00:00
|
10,000
|
BOMBAY
|
2
|
B
|
02/01/2016 00:00:00
|
07/03/2016 00:00:00
|
10,000
|
KOLKATA
|
3
|
C
|
03/01/2016 00:00:00
|
08/06/2016 00:00:00
|
10,000
|
CHENNAI
|
4
|
D
|
01/01/2016 00:00:00
|
07/06/2016 00:00:00
|
10,000
|
DELHI
|
5
|
E
|
01/01/2016 00:00:00
|
09/06/2016 00:00:00
|
12,000
|
NOIDA
|
6
|
F
|
01/01/2016 00:00:00
|
08/06/2016 00:00:00
|
15,000
|
BHUBANESWAR
|
7
|
G
|
01/01/2016 00:00:00
|
07/06/2016 00:00:00
|
11,000
|
PUNE
|
8
|
A
|
01/01/2016 00:00:00
|
06/06/2016 00:00:00
|
10,000
|
GOA
|
8
|
B
|
01/01/2016 00:00:00
|
06/06/2016 00:00:00
|
10,000
|
DELHI
|
1) selects details of all employees with a City of "Delhi" or
"Kolkata":
SELECT * FROM EMPLOYEE1 WHERE CITY IN ('KOLKATA','DELHI');
The output would
be like:
ID
|
NAME
|
START_DATE
|
END_DATE
|
SALARY
|
CITY
|
2
|
B
|
02/01/2016 00:00:00
|
07/03/2016 00:00:00
|
10,000
|
KOLKATA
|
4
|
D
|
01/01/2016 00:00:00
|
07/06/2016 00:00:00
|
10,000
|
DELHI
|
8
|
B
|
01/01/2016 00:00:00
|
06/06/2016 00:00:00
|
10,000
|
DELHI
|
No comments:
Post a Comment