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

MySQL must know that it will filter data.

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

Share

Shulou(Shulou.com)06/01 Report--

1. Use the where clause

2.where clause operator

2.1 check a single value

2.2 mismatch check

2.3 range value check

2.4 Null check

Use the where clause

Database tables generally contain a large amount of data, and there is little need to retrieve all the rows in the table. A subset of table data is usually extracted according to the needs of a specific operation or report.

For example: find rows whose age is equal to 22 years old

MariaDB [test] > select age

-> from user

-> where age=22

+-+

| | age |

+-+

| | 22 |

+-+

1 row in set (0.00 sec)

Tip: when using both the order by and where clauses, order by should be placed after where.

Where clause operator

Equal to, not equal to, less than, less than or equal to, greater than, greater than or equal to, using between between two specified values

2.1 check a single value

MariaDB [test] > select id,age,province

-> from user

-> where province = 'Beijing'

+-- +

| | id | age | province | |

+-- +

| | 1 | 22 | Beijing |

| | 4 | 14 | Beijing |

| | 7 | 45 | Beijing |

| | 11 | 29 | Beijing |

| | 13 | 24 | Beijing |

+-- +

5 rows in set (0.01 sec)

2.2 mismatch check

MariaDB [test] > select id, age, province

-> from user

-> where age 22

+-- +

| | id | age | province | |

+-- +

| | 2 | 25 | Guangdong |

| | 3 | 56 | Tianjin |

| | 4 | 14 | Beijing |

| | 5 | 36 | Guangdong |

| | 6 | 68 | Hunan |

| | 7 | 45 | Beijing |

| | 8 | 17 | Hebei |

| | 9 | 33 | Tianjin |

| | 10 | 27 | Hunan |

| | 11 | 29 | Beijing |

| | 12 | 70 | Guangdong |

| | 13 | 24 | Beijing |

+-- +

12 rows in set (0.00 sec)

2.3 range value check

MariaDB [test] > select id,age,province

-> from user

-> where age between 25 and 33

+-- +

| | id | age | province | |

+-- +

| | 2 | 25 | Guangdong |

| | 9 | 33 | Tianjin |

| | 10 | 27 | Hunan |

| | 11 | 29 | Beijing |

+-- +

4 rows in set (0.00 sec)

2.4 Null check

Tip: the null value NULL (no value) is different from 0, empty string, or space.

MariaDB [test] > select id,age,province

-> from user

-> where age IS NULL

Empty set (0.00 sec)

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

Wechat

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

12
Report