mysql query the statement that the value of a field is not empty

1.Not empty
select * from table where id <> "";
select * from table where id != "";
2. is empty
select * from table where id ="";
select * from table where isNull(id);

MySQL provides the IS NULL keyword to determine whether the value of a field is a null value (NULL). A null value is not the same as 0, and it is not the same as an empty string.

If the value of the field is null, the query condition is satisfied, and the record will be queried. If the value of the field is not null, the query condition is not satisfied.

The basic syntax for using IS NULL is as follows:

IS [NOT] NULL
mysql> SELECT `name`,`login_date` FROM tb_students_info 
    -> WHERE login_date IS NULL;
+--------+------------+
| NAME   | login_date |
+--------+------------+
| Dany   | NULL       |
| Green  | NULL       |
| Henry  | NULL       |
| Jane   | NULL       |
| Thomas | NULL       |
| Tom    | NULL       |
+--------+------------+
6 rows in set (0.01

Note: IS NULL is a whole, you cannot replace IS with “=”. If you replace IS with “=”, you will not be able to query any results, and the database system will display a prompt like “Empty set(0.00 sec)”. Similarly, IS NOT in IS NOT NULL cannot be replaced with “!=” or “<>”.

IS NOT NULL indicates that the query field value is not null for records.

mysql> SELECT `name`,login_date FROM tb_students_info 
    -> WHERE login_date IS NOT NULL;
+-------+------------+
| name  | login_date |
+-------+------------+
| Jim   | 2016-01-15 |
| John  | 2015-11-11 |
| Lily  | 2016-02-26 |
| Susan | 2015-10-01 |
+-------+------------+
4 rows in set (0.00
----------------------------------

Leave a Reply

Your email address will not be published. Required fields are marked *

en_USEnglish