MySQL must know---filter data

Source: Internet
Author: User

1. Using the WHERE clause
2.where clause operator
2.1 Checking individual values
2.2 Mismatch Check
2.3 Range Value Check
2.4 Null value Check

    1. Using the WHERE clause
      Database tables typically contain a large amount of data, and it is seldom necessary to retrieve all the rows in a table. A subset of the table data is typically extracted based on the needs of a particular operation or report.

For example: Find a line of age 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, you should have order by in the Where.

    1. WHERE clause operator
      Equal, not equal, less than, less than equals, greater than, greater than or equal to, using between between the specified two values

2.1 Checking individual values
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 |
+----+------+----------+
Rows in Set (0.00 sec)

2.3 Range Value Check

MariaDB [test]> Select Id,age,province
-From user
-where age between 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 value Check

Tip: A null value of NULL (no value) differs from 0, an empty string, or a space.

MariaDB [test]> Select Id,age,province
-From user
, where is NULL;
Empty Set (0.00 sec)

MySQL must know---filter data

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.