Home  >  Article  >  Database  >  How to Select Rows Based on Multiple Values in MySQL?

How to Select Rows Based on Multiple Values in MySQL?

DDD
DDDOriginal
2024-10-31 05:39:30518browse

How to Select Rows Based on Multiple Values in MySQL?

Selecting Multiple Values in MySQL Queries

In this scenario, you aim to retrieve specific rows based on multiple criteria, such as identifying individuals by their IDs (3 and 4) or names (andy and paul) within a table.

To achieve this, you can utilize the following syntax:

OR Condition:

SELECT * FROM table WHERE id = 3 OR id = 4

This query retrieves rows where the id column matches either 3 or 4.

IN Clause:

SELECT * FROM table WHERE id IN (3,4)

Alternatively, you can use the IN clause to specify a list of values to match. In this case, the query selects rows where the id column is either 3 or 4.

The above is the detailed content of How to Select Rows Based on Multiple Values in MySQL?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn