Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
7
Help us understand the problem. What is going on with this article?
@accakr

MySQLのNULLと空値でハマる

More than 5 years have passed since last update.

たとえば

  • 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件 → !!!!

言い訳

''自体がクソコードなわけですが、= ''!= ''が「逆」を意味しないのはいろいろと怖い

7
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
accakr
文系卒 -> SIer卒 -> 株式会社ヴァリューズでエンジニア なんだかんだインフラアーキテクチャが一番長い
valuesccg
「インターネット行動ログ分析サービス」など、デジタルマーケティング領域での新たな価値創造を通し、各企業の成長支援を行っています。エンジニア募集中。

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
7
Help us understand the problem. What is going on with this article?