The IN operator in SQL is used to check whether the specified value is in a given set. It filters the data by checking whether the value of the specified column matches the value in the set. It is suitable for finding values that match a specific value. Check if a value belongs to a known category, optimize query performance. Example: Find employees that contain one of "John", "Jane", or "Mark" as names; find products that do not contain one of "Red" or "Blue" as colors.
Meaning of IN in SQL
In SQL query language, IN operator is used to check a given value Whether it is in the specified collection. Its syntax is as follows:
<code>SELECT ... FROM table_name WHERE column_name IN (value1, value2, ...)</code>
Function
The IN operator filters data by checking whether the value of a specified column matches a given set of values. It returns all rows that match at least one value in the given set.
Advantages
The IN operator, when used with the NOT IN operator, is ideal for performing:
Example
The following query finds employees whose names contain one of "John", "Jane" or "Mark":
<code>SELECT * FROM employees WHERE name IN ('John', 'Jane', 'Mark')</code>
The following query finds employees who do not contain "Red" or "Blue" One product as color:
<code>SELECT * FROM products WHERE color NOT IN ('Red', 'Blue')</code>
Note
The above is the detailed content of What does in in sql mean?. For more information, please follow other related articles on the PHP Chinese website!