1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

SQLが従う、NULLを含めた3値論理の真理表

Posted at

はじめに

真理値 unknown はリレーショナルデータベースがNULLを採用したことで持ち込まれた第三の真理値です。

注意しないといけないことは、真理値 unknown と NULLの一種である UNKNOWN とは別物だということ。

3値論理の真理表

  • t: true
  • u: unknown
  • f: false

NOT

x NOT x
t f
u u
f t

AND

AND t u f
t f u f
u u u f
f f f f

OR

OR t u f
t t t t
u t u u
f t u f

3値論理の優先順位

上記の表を覚えるのは大変なので、以下の優先順位が出力を決定していると考えてみてはどうでしょうか?

AND

false > unknown > true

OR

true > unknown > false

これを覚えておくと、例えば「true AND unknown」の結果はunknownになるということがパッとわかると思います。

特に、ANDにunknownが含まれた場合、絶対にtrueにはならない。

ということはANDがtrueにはるのは、共にtrueの場合だけなのは、よく覚えておきましょう。

さいごに

この知識を覚えた上で、次回以降具体的なコードを例に、3値理論がいかにトリッキーかをみていきます。

参照

64 - 65p

アウトプット100本ノック実施中

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?