9.1. Logical Operators

|9.1. Logical Operators|                    |                                  |                  |                                  |
|:--------------------:|--------------------|----------------------------------|------------------|----------------------------------|
|[Prev](functions.html)|[Up](functions.html)|Chapter 9. Functions and Operators|[Home](index.html)| [Next](functions-comparison.html)|

---

## 9.1. Logical Operators

[]()[]()

 The usual logical operators are available: []() []() []() []() []() []()

```
boolean AND boolean → boolean
boolean OR boolean → boolean
NOT boolean → boolean

```

SQL uses a three-valued logic system with true, false, and `null`, which represents “unknown”. Observe the following truth tables:

|*`a`*|*`b`*|*`a`* AND *`b`*|*`a`* OR *`b`*|
|-----|-----|---------------|--------------|
|TRUE |TRUE |     TRUE      |     TRUE     |
|TRUE |FALSE|     FALSE     |     TRUE     |
|TRUE |NULL |     NULL      |     TRUE     |
|FALSE|FALSE|     FALSE     |    FALSE     |
|FALSE|NULL |     FALSE     |     NULL     |
|NULL |NULL |     NULL      |     NULL     |

|*`a`*|NOT *`a`*|
|-----|---------|
|TRUE |  FALSE  |
|FALSE|  TRUE   |
|NULL |  NULL   |

 The operators `AND` and `OR` are commutative, that is, you can switch the left and right operands without affecting the result. (However, it is not guaranteed that the left operand is evaluated before the right operand. See [Section 4.2.14](sql-expressions.html#SYNTAX-EXPRESS-EVAL) for more information about the order of evaluation of subexpressions.)

---

|      [Prev](functions.html)      |[Up](functions.html)|    [Next](functions-comparison.html)   |
|:---------------------------------|:------------------:|---------------------------------------:|
|Chapter 9. Functions and Operators| [Home](index.html) | 9.2. Comparison Functions and Operators|

 // \<![CDATA[ \<-- For SVG support if ('WebSocket' in window) { (function() { function refreshCSS() { var sheets = [].slice.call(document.getElementsByTagName("link")); var head = document.getElementsByTagName("head")[0]; for (var i = 0; i \< sheets.length; ++i) { var elem = sheets[i]; head.removeChild(elem); var rel = elem.rel; if (elem.href && typeof rel != "string" || rel.length == 0 || rel.toLowerCase() == "stylesheet") { var url = elem.href.replace(/(&|\\?)\_cacheOverride=\\d+/, ''); elem.href = url + (url.indexOf('?') \>= 0 ? '&' : '?') + '\_cacheOverride=' + (new Date().valueOf()); } head.appendChild(elem); } } var protocol = window.location.protocol === 'http:' ? 'ws://' : 'wss://'; var address = protocol + window.location.host + window.location.pathname + '/ws'; var socket = new WebSocket(address); socket.onmessage = function(msg) { if (msg.data == 'reload') window.location.reload(); else if (msg.data == 'refreshcss') refreshCSS(); }; console.log('Live reload enabled.'); })(); } // ]]\>