Help us understand the problem. What is going on with this article?

MySQLのNULLと空値でハマる

More than 3 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件 → !!!!

言い訳

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

accakr
文系卒 -> SIer卒 -> 株式会社ヴァリューズでエンジニア なんだかんだインフラアーキテクチャが一番長い
https://www.valuesccg.com/
valuesccg
「インターネット行動ログ分析サービス」など、デジタルマーケティング領域での新たな価値創造を通し、各企業の成長支援を行っています。エンジニア募集中。
https://www.valuesccg.com/
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
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  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
ユーザーは見つかりませんでした