The WHERE clause is used to filter MySQL data results and select rows that meet specific criteria by specifying conditions. Conditions can contain comparison operators, logical operators, wildcards, constants, and variables. Examples: - Filter based on age: SELECT FROM employees WHERE age > 18; - Filter based on name pattern: SELECT FROM customers WHERE name LIKE "John%"; - Filter based on multiple conditions: SELECT * FROM orders WHERE total_amount > 100 AND order_
Using the WHERE clause in MySQL
The WHERE clause is used in MySQL to filter data results A powerful tool. It allows you to specify a specific condition to select only rows that meet that condition.
Syntax
<code class="sql">SELECT column_name(s) FROM table_name WHERE condition;</code>
Usage
The WHERE clause is placed at the end of the SELECT statement, after the FROM clause. The conditions section specifies the rules for filtering the data.
Conditions
Conditions can contain the following:
Example
-- 选择所有年龄大于 18 岁的员工
SELECT * FROM employees WHERE age > 18;
-- 选择名称以 "John" 开头的所有客户
SELECT * FROM customers WHERE name LIKE "John%";
-- 选择满足以下所有条件的订单:
-- 订单总金额大于 100 美元
-- 订单日期在 2022 年 1 月 1 日之后
SELECT * FROM orders WHERE total_amount > 100 AND order_date > '2022-01-01';Note
The WHERE clause cannot be used with INSERT, UPDATE or DELETE statement. - The impact of conditions on the results depends on the order and combination of conditions.
- If you do not use an index, the WHERE clause may cause query performance to decrease.
-
The above is the detailed content of Usage of where in mysql. For more information, please follow other related articles on the PHP Chinese website!