where conditional clause
The search condition can be composed of one or more logical expressions, and the result is generally a Boolean value
Logical Operators
Operator |
grammar |
description |
and && |
a and b a && b |
Logical and two are true, the result is true |
or || |
a or b a || b |
Logical or one is true, the result is true |
not ! |
not a !a |
Logic is not true for false, false is true |
SELECT `name`,`sex` FROM student
SELECT `NAMe`, `address` FROM student WHERE `NAME` >= 95 AND `NAME`<= 100
SELECT `NAMe`, `address` FROM student WHERE `NAME` >= 95 && `NAME` <= 100
SELECT `name`,`address` FROM student WHERE `name` BETWEEN 95 AND 100
SELECT `NAMe`, `address` FROM student WHERE `NAME` != 1 AND `NAME` < 10
SELECT `NAMe`, `address` FROM student WHERE NOT `NAME` = 100 AND `NAME` > 90
Fuzzy query: comparison operators
Operator |
grammar |
description |
is null |
a is null |
If a is null, the result is true |
is not null |
a is not null |
If a is not null, the result is true |
between and |
3 between 1 and 5 |
If 3 is between 1 and 5, the result is true |
Like |
a like b |
sql matches, if a matches b, the result is true |
In |
a in (abcd, pdosa, …) |
If a is in (abcd, pdosa, …), the result is true |
SELECT `name` FROM student WHERE `name` LIKE '张%'
SELECT `name` FROM student WHERE `name` LIKE '张_'
SELECT `name` FROM student WHERE `name` LIKE '张__'
SELECT `name` FROM student WHERE `name` LIKE '%张%'
SELECT `id`,`name` FROM student WHERE `id` IN (1,2,3)
SELECT `id`,`name`,`address` FROM student WHERE `address` IN ('北京')
SELECT `name`,`address` FROM student WHERE `address`='' OR `address` IS NULL
SELECT `name`,`address`,`birthday` FROM student WHERE `birthday` IS NOT NULL
SELECT `name`,`address`,`birthday` FROM student WHERE `birthday` IS NULL