Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***************
- SQL - Filtering
- ***************/
- /*
- SQL uses a three-part logic. The possible values are TRUE, FALSE, and UNKNOWN.
- This comes into play when comparing NULL values.
- Comparing NULL to any other value (or NULL) with an equality operator will always return UNKNOWN.
- */
- -- All of the following return 0 rows:
- SELECT 'abc'
- WHERE 1 = NULL;
- SELECT 'abc'
- WHERE 1 <> NULL;
- SELECT 'abc'
- WHERE NULL = NULL;
- /*
- To compare something to NULL, use the IS operator instead.
- */
- SELECT 'abc'
- WHERE 1 IS NOT NULL;
- -- 'abc'
- SELECT 'abc'
- WHERE NULL IS NULL;
- -- 'abc'
- /*
- SQL logic is not necessarily evaluated in left-to-right order.
- This behavior can be frustrating, because while SQL can short-circuit if a statement evaluates to false,
- you can't necessarily predict the order in which the evaluation occurs.
- The main situation where this causes problems is with data type conversions.
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement