Selecting Multiple Values in MySQL
In MySQL, selecting multiple values from a table can be tricky at times. However, there are a few simple approaches to achieve this.
When selecting rows based on specific IDs, an OR condition can be used. For example, to select rows where id is either 3 or 4, the query would be:
SELECT * FROM table WHERE id = 3 OR id = 4
Another option is to use the IN operator. This allows for specifying a list of values to match. The equivalent query using IN would be:
SELECT * FROM table WHERE id IN (3,4)
These approaches can be extended to select multiple values based on any column, not just id. For instance, to select rows where name is either "andy" or "paul", the query would be:
SELECT * FROM table WHERE name = "andy" OR name = "paul"
Or using IN:
SELECT * FROM table WHERE name IN ("andy", "paul")
The above is the detailed content of How to Select Multiple Values in a MySQL Table?. For more information, please follow other related articles on the PHP Chinese website!