MySQL Where

PHP MySQL Select Where (PHP MySQL选择位置)

The SELECT statement is used to fetch data from a database. The WHERE clause is used to filter data based on specific conditions. The WHERE clause can be combined with the SELECT statement to fetch only specific data from the database. (SELECT语句用于从数据库获取数据。WHERE子句用于根据特定条件筛选数据。WHERE子句可以与SELECT语句组合,以仅从数据库获取特定数据。)

Here is the basic syntax of the SELECT statement with WHERE clause:

SELECT column1, column2, ...
FROM table_name
WHERE condition;

In the above syntax:

  • column1, column2, … are the columns you want to fetch data from. (- column1, column2,…是您要从中获取数据的列。)

  • table_name is the name of the table you want to fetch data from. (- table_name是要从中获取数据的表的名称。)

  • condition is a logical expression that determines what data to retrieve. (- condition是一个逻辑表达式,用于确定要检索的数据。)

Example

Example (示例)

Consider a table named customers with the following data:

idnameemailcountry
1John[email protected]USA
2Jane[email protected]UK
3Alice[email protected]France

Here is an example of how to use the SELECT statement with WHERE clause to retrieve only specific data from the customers table:

SELECT name, email
FROM customers
WHERE country = 'USA';

The above SELECT statement will return only the rows where the country column is equal to USA. The output will be:


nameemail
John[email protected]

Multiple Conditions

Multiple Conditions (多个条件)

You can also use multiple conditions in the WHERE clause. For example, you can retrieve all customers from the customers table who live in the USA and have an email address that ends with example.com. (您还可以在WHERE子句中使用多个条件。例如,您可以从customers表中检索居住在美国且电子邮件地址以example.com结尾的所有客户。)

SELECT name, email
FROM customers
WHERE country = 'USA'
AND email LIKE '%example.com';

The above SELECT statement will return the following output:


nameemail
John[email protected]

You can use logical operators such as AND and OR to combine multiple conditions in the WHERE clause.



请遵守《互联网环境法规》文明发言,欢迎讨论问题
扫码反馈

扫一扫,反馈当前页面

咨询反馈
扫码关注
返回顶部