Home>Article>Database> How to query multiple conditions in MySQL

How to query multiple conditions in MySQL

WBOY
WBOY Original
2022-05-26 15:22:35 12463browse

Method: 1. Use the "SELECT * FROM table name WHERE condition 1 AND condition 2..." statement to query all conditions in multiple conditions; 2. Use "SELECT * FROM table name WHERE condition 1 OR Condition 2..." statement queries the specified condition among multiple conditions.

How to query multiple conditions in MySQL

The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.

How to query multiple conditions in mysql

Conditional query

The SELECT statement can set query conditions through WHERE conditions, and the query results are records that meet the query conditions.

SQL conditional query syntax:

SELECT * FROM <表名> WHERE <条件表达式>;

Conditional expression:

1, AND , expression that satisfies condition 1 and Condition 2 is met.

The AND operator is a logical operator that combines two or more Boolean expressions, returning true only if both expressions evaluate to true. The AND operator returns false if one of the two expressions evaluates to false.

How to query multiple conditions in MySQL

##2, OR , means that either Condition 1 or Condition 2 is satisfied.

How to query multiple conditions in MySQL

NOT means records that "do not meet the condition".

To combine three or more conditions, you need to use parentheses () to indicate how to perform conditional operations.

Note: If parentheses are not added, the conditional operation is performed according to the priority of NOT, AND, and OR, that is, NOT has the highest priority, followed by AND, and finally OR. Adding parentheses changes the priority.

Extended knowledge:

Basic query

The basic query syntax of SQL: SELECT * FROM

mysql video tutorial

;The result of the SELECT query is a Two-dimensional table.The SELECT statement does not actually require a FROM clause. Although SELECT can be used for calculations, it is not the strength of SQL. However, the SELECT statement without a FROM clause has a useful purpose, which is to determine whether the current connection to the database is valid. Many detection tools will execute a SELECT 1; to test the database connection.Recommended learning:

The above is the detailed content of How to query multiple conditions 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