WHERE IN in SQL is used to check whether a column contains a specific set of values. Syntax: SELECT column_name FROM table_name WHERE column_name IN (value1, value2, ..., valueN);. It checks if each value in the column matches any value in the given list of values and returns the row if it matches, otherwise ignores the row.
Usage of WHERE IN in SQL
The WHERE IN operator is used to check whether a column contains a specific set of value. It uses the following syntax:
<code>SELECT column_name FROM table_name WHERE column_name IN (value1, value2, ..., valueN);</code>
How it works
The WHERE IN operator checks whether each value in a column matches any value in the given list of values. If there is a match, the corresponding row is returned; if there is no match, the row is ignored.
Example
Suppose we have a table called "users" with the following columns:
To find the email address of a user named "John" or "Mary", you can use the following query:
<code>SELECT email FROM users WHERE name IN ('John', 'Mary');</code>
This will return rows with the name "John" or "Mary" as follows:
<code>email ----------------- john@example.com mary@example.com</code>
Note:
The above is the detailed content of Usage of wherein in sql. For more information, please follow other related articles on the PHP Chinese website!