grammar
SELECT select_list
FROM table_name
WHERE condition
ORDER BY sort_expression
WHERE appears after the FROM clause of the SELECT statement. WHERE uses conditional judgment to filter the rows returned by the SELECT statement.
The conditional judgment value here must be TRUE or FALSE or UNKNOWN. It can be an expression that returns a logical value, or a logical expression composed of multiple or or and.
The return value of the query statement must meet the WHERE conditional judgment, and only when the conditional judgment is true can the value pass the WHERE filter.
WHERE clause execution order
If you set the column alias in the SELECT, you cannot use it in WHERE.
In addition to the SELECT statement, you can also use the WHERE clause in the UPDATE and DELETE statements to specify the rows to be updated or deleted.
Comparison and logical operators
To form conditions in the WHERE clause, you can use comparison and logical operators:
Operator | description |
---|---|
= | equal |
> | more than the |
< | Less than |
>= | greater or equal to |
<= | Less than or equal to |
<> or != | not equal to |
AND | Logically and |
OR | Logically or |
IN | Returns true if a value matches any value in the list |
BETWEEN | If a value is between a set of values, return true |
LIKE | If a value matches a pattern, return true |
IS NULL | If the value is empty, return true |
NOT | Negate the results of other operators |