The following three functions can be used for where sub-conditions, as data deletion, updated record positioning basis.
Such as:
SELECT * from Usergrade WHERE ISNULL (USERNAME);
One, ISNULL (expr)
If expr is null, then the return value of IsNull () is 1, otherwise the return value is 0.
mysql> select isnull (1 /0 ) as result; +--------+| Result |+--------+| 1 |+--------+1 row in set (0.00 sec) MySQL > select isnull (0 / 1 ) as result; +--------+| Result |+--------+| 0 |+--------+1 row in set (0.00 sec)
The comparison of NULL values using = is usually wrong.
The IsNull () function has some of the same characteristics as the IS null comparison operator. See the description for is null.
Second, ifnull (EXPR1,EXPR2)
If EXPR1 is not NULL, the return value of EXPR2 is EXPR2, regardless of whether the value of Null,ifnull () is expr1;
The return value of Ifnull () is either a number or a string, depending on the context in which it is used.
Mysql> SELECT Ifnull (1,0);+-------------+| Ifnull (1,0) |+-------------+|1|+-------------+1Rowinch Set(0.01sec) MySQL> SELECT ifnull (NULL,Ten); +-----------------+| Ifnull (NULL,Ten) |+-----------------+|Ten|+-----------------+1Rowinch Set(0.00sec) MySQL> SELECT ifnull (1/0,Ten); +----------------+| Ifnull (1/0,Ten) |+----------------+|10.0000|+----------------+1Rowinch Set(0.00sec) MySQL> SELECT ifnull (1/0,'Yes'); +-------------------+| Ifnull (1/0,'Yes') |+-------------------+| Yes |+-------------------+1Rowinch Set(0.00sec) MySQL> SELECT ifnull (1,'Yes'); +-----------------+| Ifnull (1,'Yes') |+-----------------+|1|+-----------------+1Rowinch Set(0.00Sec
Iii. Nullif (expr)
If EXPR1=EXPR2 is true, the return value is NULL, otherwise the return value is EXPR1.
Mysql>SelectNullif (1,1);+-------------+| Nullif (1,1) |+-------------+| NULL |+-------------+1Rowinch Set(0.00sec) MySQL>SelectNullif ('a',1);+---------------+| Nullif ('a',1) |+---------------+| A |+---------------+1Rowinch Set,1Warning (0.00Sec
Mysql-isnull (), Ifnull (), and Nullif () functions