The operator expresses filtering between several conditions. It is an alternative to OR.
Structure:
SELECT column_name FROM table_name WHERE column_name IN pattern;
Or used for subselect:
SELECT column_name FROM table_name WHERE column_name IN (SELECT column_name FROM table_name);
Example1:
We have a table Customer with this data:
CustomerID | Name | Hair | Salary |
---|---|---|---|
1 | Alechandro | brown | 100 |
2 | Katerina | blonde | 150 |
3 | Lucie | blonde | 30 |
4 | Thomas | black | 40 |
5 | Theodor | black | 120 |
6 | Thomassino | black | 99 |
7 | Knor | brown | 50 |
8 | Thor | blonde | 10 |
9 | Lucie | pink | 70 |
SELECT name FROM Customer WHERE hair IN ('blonde', 'brown');
NAME |
---|
Alechandro |
Katerina |
Lucie |
Knor |
Thor |
We can also write it in this longer form:
SELECT name FROM Customer WHERE hair = 'blonde' or hair = 'brown';
Example2:
SELECT name FROM Customer WHERE hair NOT IN ('blonde', 'brown');
NAME |
---|
Thomas |
Theodor |
Thomassino |
Lucie |
Example3:
SELECT name FROM Customer WHERE hair IN (SELECT name FROM Employees );
Thor is also in the Customer table and the Employees table.
We have a table Customer with this data:
CustomerID | Name | Hair | Salary |
---|---|---|---|
1 | Alechandro | brown | 100 |
2 | Katerina | blonde | 150 |
3 | Lucie | blonde | 30 |
4 | Thomas | black | 40 |
5 | Theodor | black | 120 |
6 | Thomassino | black | 99 |
7 | Knor | brown | 50 |
8 | Thor | blonde | 10 |
9 | Lucie | pink | 70 |
Table Employee:
EMPLOYEEID | NAME | HAIR |
---|---|---|
1 | Julia | brown |
2 | Thor | blonde |
3 | Bob | blonde |
Here is Select result:
NAME |
---|
Alechandro |
Knor |
Katerina |
Lucie |
Thor |
I give people clear, functional, and proven instructions. I gently guide them so that they can fulfill their IT dreams.