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.
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 <条件表达式>;
Copy after login
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.
##2, OR , means that either Condition 1 or Condition 2 is satisfied.
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 ; 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: mysql video tutorial
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!