SQL operators learn --IN

IN role

IN operator allows you to specify multiple values ​​in the WHERE clause.

IN OR operator is shorthand for a plurality of conditions.

IN syntax

SELECT column_name(s) FROM table_name 

WHERE column_name IN (value1, value2, ...);

or

SELECT column_name(s) FROM table_name 

WHERE column_name IN (SELECT STATEMENT);

 

Sample Database

Data selection from the "Customers" table:

 

 

Examples of IN

The following SQL statement selects provinces located in the "Shanghai", "Beijing" and "Guangdong Province" of all customers:

Code Example:

SELECT * FROM Customers 
WHERE 省份 IN ('上海市', '北京市', '广东省');

result:

You can see that all provinces IN inside data columns

 

The following SQL statement choose not to, "Zhejiang Province", the "Shanghai" or "Beijing" to all customers:

Code Example:

SELECT * FROM Customers 
WHERE 省份 NOT IN ('浙江省', '上海市', '北京市');

result:

You can see that column provinces excluded those data IN inside, because it is NOT, it is to exclude the meaning.

 

The following SQL statement to select all customers from the same city as a supplier "Suppliers":

We look at the content providers "Suppliers" table of:

Code Example:

SELECT * FROM Customers 
WHERE 城市 IN (SELECT 城市 FROM Suppliers);

result:

We see suppliers Suppliers table only city to Shanghai, only with customers but also for the city Customers table can correspond to the data of Shanghai. So here the role of IN is to take two tables of data will have to be check out.

 

annotation

IN the content you will need to find a role is listed on the back of the brackets, but also the result of the sub-query can be placed in brackets, so you only find in line with IN brackets content to play the role of screening. IN addition which can put various types of data, including the type commonly date, characters, numerical values.

Guess you like

Origin www.cnblogs.com/-wenli/p/11566989.html
Recommended