Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. /***************
  2. SQL - Filtering
  3. ***************/
  4.  
  5. /*
  6. SQL uses a three-part logic. The possible values are TRUE, FALSE, and UNKNOWN.
  7.  
  8. This comes into play when comparing NULL values.
  9. Comparing NULL to any other value (or NULL) with an equality operator will always return UNKNOWN.
  10. */
  11. -- All of the following return 0 rows:
  12.  
  13. SELECT 'abc'
  14. WHERE 1 = NULL;
  15.  
  16. SELECT 'abc'
  17. WHERE 1 <> NULL;
  18.  
  19. SELECT 'abc'
  20. WHERE NULL = NULL;
  21.  
  22. /*
  23. To compare something to NULL, use the IS operator instead.
  24. */
  25.  
  26. SELECT 'abc'
  27. WHERE 1 IS NOT NULL;
  28. -- 'abc'
  29.  
  30. SELECT 'abc'
  31. WHERE NULL IS NULL;
  32. -- 'abc'
  33.  
  34.  
  35.  
  36. /*
  37. SQL logic is not necessarily evaluated in left-to-right order.
  38. This behavior can be frustrating, because while SQL can short-circuit if a statement evaluates to false,
  39. you can't necessarily predict the order in which the evaluation occurs.
  40.  
  41. The main situation where this causes problems is with data type conversions.
  42. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement