Home >Database >Mysql Tutorial >What is used to implement the selection operation in the sql select statement?
In the sql select statement, "WHERE" is used to implement the selection operation. In SQL query statements, the WHERE clause is used to specify query conditions. Only tuples that meet the conditions will appear in the result set.
The operating environment of this tutorial: Windows 7 system, mysql version 5.8, Dell G3 computer.
In the sql select statement, "WHERE" is used to implement the selection operation.
(Recommended tutorial: mysql video tutorial)
In sql, the WHERE clause is used to extract records that meet specified conditions. If you need to conditionally query data from the data table, you can use the WHERE keyword to specify the query conditions.
The WHERE clause limits the return of data in the table. Data that meets the conditions behind where will be selected, and statements that do not meet the where conditions will be filtered out.
The syntax format for using the WHERE keyword is as follows:
WHERE 查询条件
The query conditions can be:
With comparison Query conditions for operators and logical operators
Query conditions with BETWEEN AND keyword
Query conditions with IS NULL keyword
Query conditions with IN keyword
Query conditions with LIKE keyword
Below The operator can be used in the WHERE clause:
Note: In some versions of SQL, the operator can be written as !=.
Use WHERE clause
1. Single condition query statement
Single condition refers to There is only one query condition after the WHERE keyword.
Example: Query the names of students whose age is less than 22 in the tb_students_info data table
mysql> SELECT name,age FROM tb_students_info -> WHERE age<22; +------+------+ | name | age | +------+------+ | John | 21 | +------+------+ 1 row in set (0.05 sec)
You can see that the values of the age field of all records in the query results are less than 22 years old, and are greater than or equal to Records for the 22-year-old were not returned.
2. Multi-condition query statement
There can be multiple query conditions after the WHERE keyword, which can make the query results more accurate. Multiple query conditions are separated by logical operators AND (&&), OR (||) or XOR.
AND: Records will be queried only when they meet all query conditions.
OR: Records will be queried only when they meet any query condition.
XOR: The record will be queried only when it meets one of the conditions and does not meet the other condition.
Example: Query student information in the tb_students_info table whose age is greater than 21 and height is greater than or equal to 175
mysql> SELECT name,age,height FROM tb_students_info -> WHERE age>21 AND height>=175; +--------+------+--------+ | name | age | height | +--------+------+--------+ | Henry | 23 | 185 | | Jim | 24 | 175 | | Thomas | 22 | 178 | +--------+------+--------+ 3 rows in set (0.00 sec)
You can see that the age field of all records in the query results Both are greater than 21 and the height field is greater than or equal to 175.
For more programming related knowledge, please visit: Programming Video! !
The above is the detailed content of What is used to implement the selection operation in the sql select statement?. For more information, please follow other related articles on the PHP Chinese website!