2012-05-15 101 views
2

這看起來像一個簡單的問題。我想查詢MySQL數據庫中列的位置爲空,「」或空白處。我現在這樣做的方式是這樣的:Mysql查詢哪裏列是空白?

select * from table where column_1 is null or REPLACE(column_1," ","") = ""; 

有沒有更好的方法來做到這一點?

謝謝!

回答

8

您當前的方法不會顯示,因爲three valued logic

select * from table where column_1 IS NULL OR TRIM(column_1) = ''; 

select * from table where COALESCE(TRIM(column_1), '') = ''; 
+0

是哎呀對不起忘了,在這篇文章中,YES! TRIM功能,這就是我想要的。 –

1

空值試試這個:

select * from table where column_1 is null or column_1 = '';