Skip to Main Content

Write Great SQL Office Hours

Free tips and training every month! Subscribe for reminders and more from Office Hours. FAQ

Header container

June 21, 2022

13:00 UTC   Start Times Around the World

Subscribe to be notified of changes to sessions and give us feedback!

Having trouble watching the video on this page? Open the video in your browser.

Description

How to handle NULL in SQL
The NULL value represents missing or not applicable information. But using it introduces three-valued logic. This can lead to surprising outcomes when handled incorrectly.

This session covered the problems using NULL brings and how to avoid these. Highlights include:

- 00:30 - The problem with val = null
- 05:30 - Demo of problems and quirks with null
- 10:50 - Nulls in aggregate functions
- 16:30 - Nulls in check constraints
- 18:40 - Nulls in ORDER BY
- 20:50 - Why does null exist?
- 22:10 - Examples of not applicable/missing information and ways to change the schema to avoid null
- 32:40 - Handling end dates for currently active rows - null vs separate tables vs magic values
- 41:00 - The problem with magic values
- 45:00 - Situations where nulls can still appear when all columns are mandatory: outer joins, new columns, and window functions
- 47:30 - Demo of nulls in outer joins
- 48:45 - Nulls returned by window functions
- 50:00 - Mapping nulls to non-null values
- 55:40 - How to include nulls when searching for rows less than some value
- 1:00:30 - Summary

Your Experts

  • #SELECTION#
    Chris Saxon

    Chris Saxon   

    Chris Saxon is an Oracle Developer Advocate and quizmaster on Dev Gym. His job is to help you get the best out of the Oracle Database and have fun with SQL! He's also part of the answer team on Ask TOM and creates YouTube videos at The Magic of SQL channel.
    #MISC#
    #ACTIONS#