Home >Database >Mysql Tutorial >How to Select Multiple Rows in MySQL Based on Specific Values?
Selecting Multiple Rows in MySQL using the IN Operator
When working with SQL databases, there are often instances where you need to retrieve specific rows based on multiple criteria. Let's consider the following scenario: You want to select rows from a table where the ID column contains either the value 3 or 4.
To accomplish this, MySQL provides the IN operator, which allows you to specify a list of values to match against. The syntax for this query is:
SELECT * FROM table_name WHERE column_name IN (value1, value2, ...)
In your case, where you want to select rows with IDs 3 or 4, the query would be:
SELECT * FROM table WHERE id IN (3, 4)
This query will return all rows where the ID column equals 3 or 4.
Another alternative is to use the OR operator, expressed as a series of individual conditions:
SELECT * FROM table WHERE id = 3 OR id = 4
Both methods will provide the desired result of selecting rows based on multiple values.
The above is the detailed content of How to Select Multiple Rows in MySQL Based on Specific Values?. For more information, please follow other related articles on the PHP Chinese website!