MySQL uses the where command to qualify data query criteria.
Syntax: SELECT Property 1, Property 2 from table name WHERE condition 1 OR Condition 2 and Condition 3
Description: Where the same applies to update, delete and other commands;
Using or, and implementing the data query under the multi-limit condition;
where execution is executed from left to right, when the amount of data is small, do not consider, but the amount of data to consider the order of the conditions, at this time should abide by a principle: the more the exclusion of the conditions placed in the first;
Using the primary key as the qualification for the query is very fast.
Operator Description Table (A=10,B=20)
Operator |
Describe |
Example description |
= |
Equals, detects whether two values are equal and returns true if they are equal |
(A = B) returns false |
<>,!= |
does not equal, detects whether two values are equal and returns true if not equal |
(A! = B) returns True |
> |
Greater than, detects whether the left value is greater than the right value, and returns True if the value on the left is greater than the right value |
(A > B) return False |
< |
Less than, detects whether the left value is less than the right value, and returns True if the left value is less than the right value |
(A < B) returns True |
>= |
No less than, detects whether the left value is not less than the right value, and returns True if the left value is not less than the right value. |
(A >= B) returns false |
<= |
No greater than, detects whether the left value is not greater than the right value, and returns True if the left value is not greater than the right value. |
(A <= B) returns True |
Between .... And .... |
Falls within the specified range |
where num between 3 and 5 |
Not between ... And ... |
Not within the scope of the limit |
where num not between 3 and 5 |
In (item 1, item 2, item 3 ...) |
Value within the specified item |
where Num in (3,5,6) |
Not in (item 1, item 2, item 3 ...) |
Value is not within the specified item |
where num not in (3,5,6) |
Is NULL |
Null-valued identifier |
where name is null |
is not NULL |
Non-null value qualifier |
Where name is NOT NULL |
Not, and, or |
Reverse, with, or, priority Not>and>or, for multiple logical connections |
where Num>2 and Num<6 |
Like |
Search matches, often used in conjunction with pattern-matching characters |
—— |
Not-like |
The inverse meaning of like |
—— |
% |
Pattern match, representing any string |
Where username like '%user ' |
If the value of a or B is a character type, you need to add "" or ".
By default, the where statement is case-insensitive and requires a binary-enforced distinction.
Example:
Mysql>Select Num,name from Courses where name=. ' Language ';+-----+--------+| num | Name |+-----+--------+| 2 | Chinese |+-----+--------+mysql>SELECT * from tutorials_tbl WHERE tutorial_author= ' Sanjay ';+-------------+----------------+-----------------+-----------------+| tutorial_id | Tutorial_title | Tutorial_author | Submission_date |+-------------+----------------+-----------------+-----------------+| 3 | JAVA Tutorial | Sanjay | 2007-05-21 |+-------------+----------------+-----------------+-----------------+| 6 | JAVA Tutorial | SANJAY | 2007-05-26 |+-------------+----------------+-----------------+-----------------+1 rows in Set (0.01 sec) mysql>SELECT * from tutorials_tbl WHERE BINARY tutorial_author= ' Sanjay '; Enforce case sensitivity+-------------+----------------+-----------------+-----------------+| tutorial_id | Tutorial_title | Tutorial_author | Submission_date |+-------------+----------------+-----------------+-----------------+| 3 | JAVA Tutorial | Sanjay | 2007-05-21 |+-------------+----------------+-----------------+-----------------+
Mysql> Select Num,name from courses where num>2 and num<5;
+-----+--------+
| num | name |
+-----+--------+
| 3 | English |
| 4 | Chemistry |
+-----+--------+
2 rows in Set (0.00 sec)
Mysql> Select Num,name from courses where not num>2;
+-----+--------+
| num | name |
+-----+--------+
| 1 | Math |
| 2 | language |
+-----+--------+
2 rows in Set (0.00 sec)
Mysql> SELECT * FROM courses WHERE name is like '% text ';
+-----+--------+-----------------+
| num | name | Submission_date |
+-----+--------+-----------------+
| 2 | language | 2018-01-30 |
+-----+--------+-----------------+
1 row in Set (0.00 sec)
MySQL where command