我需要获取MyField
为空或者可能包含空格的所有行。
我尝试了以下内容:
SELECT * FROM `myTable` WHERE `MyField` = ""
这在phpMyAdmin中运行正常,但由于某些原因不适用于PHP ..
SELECT * FROM `myTable` WHERE `MyField` <> ""
我不确定这是如何工作的,但会返回MyField
不为空的行
SELECT * FROM `myTable` WHERE LTRIM(RTRIM(`MyField`)) = ""
清空结果集
这样做的正确方法是什么?
答案 0 :(得分:6)
TRIM function完成工作:
mysql> SELECT * FROM users;
+----+------+
| id | name |
+----+------+
| 1 | |
| 2 | |
| 3 | test |
+----+------+
3 rows in set (0.00 sec)
mysql> SELECT * FROM users WHERE TRIM(name)='';
+----+------+
| id | name |
+----+------+
| 1 | |
| 2 | |
+----+------+
2 rows in set (0.00 sec)
答案 1 :(得分:1)
字段默认为NULL吗?
如果是,你试试:
WHERE myfield IS NULL OR myfield = "";
答案 2 :(得分:0)
SELECT * FROM `myTable` WHERE `MyField` != "";