Home >Database >Mysql Tutorial >Usage of in in mysql
IN operator is used to check whether a value is contained in a list of values. The syntax is: SELECT * FROM table_name WHERE column_name IN (value1, value2, ..., valueN); The IN operator can be used with value lists, variables or subqueries, and supports multiple value type comparisons. It is more efficient than the OR operator, especially when the list contains multiple values.
Usage of IN
in MySQL
Question: IN# What is the role of ## operator in MySQL?
Answer: IN operator is used to check whether a value is contained in a list of values. The syntax is:
<code>SELECT * FROM table_name WHERE column_name IN (value1, value2, ..., valueN);</code>
Detailed explanation:
##IN The operator compares a value to a list of values. The expression is true if the value matches any value in the list. Otherwise, the expression is false.
Get students with grades A, B or C:
<code>SELECT * FROM students WHERE grade IN ('A', 'B', 'C');</code>IN
Operator supports subquery : <pre class="brush:php;toolbar:false"><code>SELECT * FROM students WHERE grade IN (SELECT grade FROM grades WHERE score > 80);</code></pre>
The value list can contain any number of values, separated by commas. The OR
operator, especially when the list contains multiple values.
If the
The above is the detailed content of Usage of in in mysql. For more information, please follow other related articles on the PHP Chinese website!