Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The usage of WHERE clause in MySQL

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "the usage of WHERE clause in MySQL". The content of the explanation in this article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn the usage of WHERE clause in MySQL.

MySQL WHERE clause

We know that SQL SELECT statements are used to read data from the MySQL table.

To conditionally select data from a table, you can add a WHERE clause to the SELECT statement.

Grammar

The following is the general syntax for SQL SELECT statements to read data from a data table using the WHERE clause:

SELECT field1, field2,...fieldN FROM table_name1, table_ name2...[WHERE condition1 [AND [OR]] condition2.

You can use one or more tables in the query statement, using commas, splits, and where statements to set query conditions.

You can specify any condition in the WHERE clause.

You can specify one or more conditions using AND or OR.

The WHERE clause can also be applied to SQL's DELETE or UPDATE commands.

The WHERE clause is similar to the if condition in a program language, reading the specified data according to the field values in the MySQL table.

The following is a list of operators that can be used in the WHERE clause.

The example in the following table assumes that An is 10 and B is 20.

The operator describes the instance = equal sign, detects whether two values are equal, and returns true (A = B) if equal returns false. ,! = is not equal, checks whether the two values are equal, and returns true (A! = B) if they are not equal. Returns true. > greater than sign, check whether the value on the left is greater than the value on the right, and return true (A > B) if the value on the left is greater than the value on the right. Return false. The greater than or equal sign detects whether the value on the left is greater than or equal to the value on the right, and returns true (A > = B) if the value on the left is greater than or equal to the value on the right. Return false. SELECT * from runoob_tbl WHERE BINARY runoob_author='runoob.com';Empty set (0.01sec) mysql > SELECT * from runoob_tbl WHERE BINARY runoob_author='RUNOOB.COM' +-+ | runoob_id | runoob_title | runoob_author | submission_date | +- -+-+ | 3 | JAVA tutorial | RUNOOB.COM | 2016-05-06 | | 4 | Learning Python | RUNOOB.COM | 2016-03-06 | +-+ 2 rows in set (0.01sec)

The BINARY keyword is used in the instance, which is case-sensitive, so the query condition of runoob_author='runoob.com' has no data.

Use PHP script to read data

You can use the mysqli_query () of the PHP function and the same SQL SELECT command with the WHERE clause to get the data.

This function is used to execute the SQL command and then output the data of all queries through the PHP function mysqli_fetch_array ().

Example

The following example returns a record using the runoob_author field value of RUNOOB.COM from the runoob_tbl table:

MySQL WHERE clause test:

The output is as follows:

Thank you for your reading. The above is the content of "the usage of WHERE clause in MySQL". After the study of this article, I believe you have a deeper understanding of the usage of WHERE clause in MySQL, and the specific use needs to be verified by practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report