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

What are the query conditions in MySQL

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

Today, I will talk to you about the query conditions in MySQL, which may not be well understood by many people. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.

Conditions

Use the where clause to filter the data in the table, and the row with the result of true appears in the result set

The syntax is as follows:

Select * from table name where condition

Example:

Select * from students where id=1

Multiple operators are supported after where for conditional processing.

Comparison operator

Logical operator

Fuzzy query

Range query

Empty judgment

Comparison operator

Equal to: =

Greater than: >

Greater than or equal to: > =

Less than: <

Less than or equal to: 3

Example 2: students whose query number is less than 4

Select * from students where id 3 and gender=0

Example 6: students whose query number is less than 4 or have not been deleted

Select * from students where id < 4 or is_delete=0

Fuzzy query

Like

% represents any number of arbitrary characters

_ represents an arbitrary character

Example 7: inquire about a student surnamed Huang

Select * from students where name like 'Yellow%'

Ex. 8: inquire about students surnamed Huang and "first name" is one word

Select * from students where name like 'Huang _'

Example 9: inquire about a student surnamed Huang or Jing

Select * from students where name like 'Huang%' or name like'% Jing'

Range query

In means to be in a discontinuous range.

Example 10: a student whose query number is 1 or 3 or 8

Select * from students where id in (1, 3, 8)

Between... And... Denote in a continuous range

Example 11: inquire about students numbered 3 to 8

Select * from students where id between 3 and 8

Example 12: boys with query numbers 3 to 8

Select * from students where (id between 3 and 8) and gender=1

Empty judgment

Note: null is different from''.

Null is null

Example 13: inquire about students who do not fill in their height

Select * from students where height is null

Judge non-empty is not null

Example 14: inquire about the students whose height has been filled in

Select * from students where height is not null

Example 15: inquire about the boy who filled in the height

Select * from students where height is not null and gender=1

Priority

The order of priority from high to low is: parentheses, not, comparison operator, logical operator

And is calculated before or. If it appears at the same time and wants to calculate or first, it needs to be combined with ().

After reading the above, do you have any further understanding of the query conditions in MySQL? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

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