たとえば
- MySQL 5.6
- hoge varchar(2) NULL可
- 100件のレコードのうち、10件がNULL、90件が"AA"
ハマる
-
select count(1) from tablename where hoge is null: 10件
→ わかる -
select count(1) from tablename where hoge is not null: 90件
→ わかる -
select count(1) from tablename where hoge = 'AA': 90件
→ わかる -
select count(1) from tablename where hoge = '': 0件
→ わかる -
select count(1) from tablename where hoge != '': 90件
→ !!!!
言い訳
''自体がクソコードなわけですが、= ''と!= ''が「逆」を意味しないのはいろいろと怖い