Data filtering through query conditions

In the previous article, we introduced basic query statements and learned how to use SELECT and FROM to query data in a table.

However, in practical applications, it is usually not necessary to return all the data in the table, but only to find out the results that meet certain conditions. For example, the sales of employees in a department or a product in the last few days. In SQL, data can be filtered by query conditions.

Query conditions

In the SQL statement, use the keyword WHERE to specify the filter conditions of the query. The following statement only returns the information of the employee whose name is "Liu Bei":

SELECT *
  FROM employee
 WHERE emp_name = '刘备';

Among them, WHERE is located after FROM and is used to specify one or more filter conditions; only data that meets the conditions will be returned, and other data will be ignored. The result of this statement is as follows:

avatar

In SQL, the WHERE clause is also called a predicate.

This operation of filtering data through query conditions is called selection in relational operations . It is a horizontal selection for a table, and rows that meet the conditions are reserved for generating a new table. The following is a schematic diagram of the selection operation:

avatar

Among the query conditions, the most frequently used is the data comparison operation.

Comparison operator

Comparison operators can compare the size of two values, including

Guess you like

Origin blog.csdn.net/horses/article/details/108729115