[Introduction]
Xiao Bian today to summarize the summary of relevant knowledge SQL WHERE clause involved
【text】
Results using the filter itself WHERE
Id | Name | DateOfBirth | Adress |
3 | Sofia | 1997-09-01 | USA |
1 | Bella | 1999-08-07 | CN |
2 | Edward | 1998-04-20 | CN |
4 | Jacob | 1998-11-28 | FA |
A specified condition .WHERE +
SELECT Id, Name, DateOfBirth, Adress
FROM MyTable
WHERE Id=1;
查询Id为1的学生
Two operator .WHERE +
1. The operator "<"
SELECT Id, Name, DateOfBirth
FROM MyTable
WHERE DateOfBirth < '2000-01-01';
查询出生在2000年之前的学生
2. The operator "AND"
SELECT Id, Name, DateOfBirth
FROM MyTable
WHERE DateOfBirth > '1998-01-01' AND DateOfBirth <'1999-01-01';
查询出生在1998-1999年之间的学生
3. The operator "="
SELECT Id, Name, Adress
FROM MyTable
WHERE Adress ='FA';
查询住在FA的学生
4. The operator "or"
SELECT Id, Name, Adress
FROM MyTable
WHERE Id=3 or Adress='CN';
查询Id为3,或者居住在CN的学生信息
The operator "like", when used in conjunction with the need to use the wildcard "%"
a%: query data beginning with the letter a
% A: query data ending in the letter a
% A%: query data includes the letter a
SELECT Id, Name, Adress
FROM MyTable
WHERE Adress like 'U%';
查询地址中以字母“U”开头的学生
SELECT Id, Name, Adress
FROM MyTable
WHERE Adress like '%N';
查询地址中以字母“N”结尾的学生
SELECT Id, Name, Adress
FROM MyTable
WHERE Adress like '%A%';
查询地址中包含字母“A”的学生
6. Operator "BETWEEN"
SELECT Id, Name, Adress
FROM MyTable
WHERE Id BETWEEN 2 AND 4;
查询Id在2到3之间的学生信息
7. Operator "not"
SELECT Id, Name, Adress
FROM MyTable
WHERE not Adress='CN';
查询不居住在CN的学生信息
【to sum up】
In the WHERE clause can use operator
Operators | Explanation |
< | Less than |
> | more than the |
= | equal |
AND | Juxtaposed |
OR | or |
NOT | Does not contain |
BETWEEN | It represents the range |
LIKE | Special inquiry |