Available in versions: Dev (3.20) | Latest (3.19) | 3.18 | 3.17 | 3.16 | 3.15 | 3.14 | 3.13 | 3.12 | 3.11 | 3.10
Conditional expressions
Applies to ✅ Open Source Edition ✅ Express Edition ✅ Professional Edition ✅ Enterprise Edition
Conditions or conditional expressions are widely used in SQL and in the jOOQ API. They can be used in
- The CASE expression
- The JOIN clause (or
JOIN .. ON
clause, to be precise) of a SELECT statement, UPDATE statement, DELETE statement - The WHERE clause of a SELECT statement, UPDATE statement, DELETE statement
- The CONNECT BY clause of a SELECT statement
- The HAVING clause of a SELECT statement
- The MERGE statement's ON clause
Boolean types in SQL
Before SQL:1999, boolean types did not really exist in SQL. They were modelled by 0 and 1 numeric/char values. With SQL:1999, true booleans were introduced and are now supported by most databases. In short, these are possible boolean values:
-
1
orTRUE
-
0
orFALSE
-
NULL
orUNKNOWN
It is important to know that SQL differs from many other languages in the way it interprets the NULL
boolean value. Most importantly, the following facts are to be remembered:
-
[ANY] = NULL
yieldsNULL
(notFALSE
) -
[ANY] != NULL
yieldsNULL
(notTRUE
) -
NULL = NULL
yieldsNULL
(notTRUE
) -
NULL != NULL
yieldsNULL
(notFALSE
)
For simplified NULL
handling, please refer to the section about the DISTINCT predicate.
Note that jOOQ does not model these values as actual column expression compatible.
Table of contents
- 3.11.1.
- Condition building
- 3.11.2.
- TRUE and FALSE condition
- 3.11.3.
- BOOLEAN columns
- 3.11.4.
- AND, OR, NOT boolean operators
- 3.11.5.
- Boolean operator precedence
- 3.11.6.
- Comparison predicate
- 3.11.7.
- Comparison predicate (degree > 1)
- 3.11.8.
- Quantified comparison predicate
- 3.11.9.
- BETWEEN predicate
- 3.11.10.
- BETWEEN predicate (degree > 1)
- 3.11.11.
- DISTINCT predicate
- 3.11.12.
- DISTINCT predicate (degree > 1)
- 3.11.13.
- DOCUMENT predicate
- 3.11.14.
- EXISTS predicate
- 3.11.15.
- IN predicate
- 3.11.16.
- IN predicate (degree > 1)
- 3.11.17.
- JSON predicate
- 3.11.18.
- JSON_EXISTS predicate
- 3.11.19.
- LIKE predicate
- 3.11.20.
- Quantified LIKE predicate
- 3.11.21.
- NULL predicate
- 3.11.22.
- NULL predicate (degree > 1)
- 3.11.23.
- OVERLAPS predicate
- 3.11.24.
- SIMILAR TO predicate
- 3.11.25.
- Spatial predicates
- 3.11.25.1.
- ST_Contains
- 3.11.25.2.
- ST_Crosses
- 3.11.25.3.
- ST_Disjoint
- 3.11.25.4.
- ST_Equals
- 3.11.25.5.
- ST_Intersects
- 3.11.25.6.
- ST_IsClosed
- 3.11.25.7.
- ST_IsEmpty
- 3.11.25.8.
- ST_Overlaps
- 3.11.25.9.
- ST_Touches
- 3.11.25.10.
- ST_Within
- 3.11.26.
- UNIQUE predicate
- 3.11.27.
- XMLEXISTS predicate
- 3.11.28.
- Query By Example (QBE)
previous : next |
References to this page
- The query DSL type
- Mutability (historic)
- JOIN operator
- WHERE clause
- UPDATE .. WHERE
- DELETE .. WHERE
- Bitwise functions
- JSON functions
- XML functions
- Tuples or row value expressions
- Condition building
- TRUE and FALSE condition
- AND, OR, NOT boolean operators
- EXISTS predicate
- IN predicate
- NULL predicate
- Dynamic SQL
- Optional column expressions
- Optional conditional expressions
- Plain SQL
- SQL Parser Listener
- Trivial predicates
- Kotlin BOOLEAN value expressions
- BOOLEAN data type
Feedback
Do you have any feedback about this page? We'd love to hear it!