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
- 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.
- 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