30
23

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 5 years have passed since last update.

SQLは3値論理 (達人に学ぶSQLより)

Last updated at Posted at 2014-05-01

#SQLは3値論理

##SQLはtrue, false, unknownの3値論理である。

3値論理になる理由はNULLがあるから。
NULLは値でも変数でもない。
比較述語を使えるのは比較する物が値の時だけ。
NULLを正しく判別するためにはISNULLを使う
下記は全てunknownになる

  • data = NULL
  • data > NULL
  • data < NULL
  • data <> NULL
  • NULL = NULL

###NOTの真理値表

x NOT x
true false
NULL unknown
false true

###ANDの真理値表

x true unknown false
true true unknown false
NULL unknown unknown false
false false false false

###ORの真理値表

x true unknown false
true true true true
NULL true unknown unknown
false true unknown false

###NOT INはNULLが含まれると結果は空になる
###EXISTSはNULLがあってもtrueとfalseしか返さない

達人に学ぶSQL徹底指南書より

30
23
1

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
30
23

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?