Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Understanding Null Functions | Null Functions
Functions in SQL

bookUnderstanding Null Functions

Understanding how SQL handles NULL values is essential for writing reliable queries. In SQL, NULL represents missing or unknown data. Unlike zero or an empty string, NULL is a special marker that means the value does not exist. If you do not handle NULL values properly, you might get unexpected results when filtering, aggregating, or performing calculations. This is especially important in real-world databases, where missing information is common.

123456789
-- Find employees who do not have a bonus assigned SELECT name, department FROM employees WHERE bonus IS NULL; -- Find employees who have a bonus assigned SELECT name, bonus FROM employees WHERE bonus IS NOT NULL;
copy

SQL provides several functions to work with NULL values effectively. The IFNULL function returns a specified value if the expression is NULL; otherwise, it returns the expression itself. The COALESCE function returns the first non-null value in a list of expressions, making it useful for providing fallback values. The NULLIF function compares two expressions and returns NULL if they are equal; otherwise, it returns the first expression. These functions help you manage missing data and prevent errors in your queries.

123
-- Show each employee's bonus, using 1000.00 as a default if bonus is NULL SELECT name, COALESCE(bonus, 1000.00) AS bonus FROM employees;
copy

1. Which function returns the first non-null value?

2. What does NULLIF do in a query?

3. Fill in the blanks to filter rows where bonus is NULL.

question mark

Which function returns the first non-null value?

Select the correct answer

question mark

What does NULLIF do in a query?

Select the correct answer

question-icon

Fill in the blanks to filter rows where bonus is NULL.

SELECT name FROM employees WHERE bonus ;
Alice Johnson
Bob Smith
Eve Black
Hannah King
Jackie Miller

Click or drag`n`drop items and fill in the blanks

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 5. Kapittel 1

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

bookUnderstanding Null Functions

Sveip for å vise menyen

Understanding how SQL handles NULL values is essential for writing reliable queries. In SQL, NULL represents missing or unknown data. Unlike zero or an empty string, NULL is a special marker that means the value does not exist. If you do not handle NULL values properly, you might get unexpected results when filtering, aggregating, or performing calculations. This is especially important in real-world databases, where missing information is common.

123456789
-- Find employees who do not have a bonus assigned SELECT name, department FROM employees WHERE bonus IS NULL; -- Find employees who have a bonus assigned SELECT name, bonus FROM employees WHERE bonus IS NOT NULL;
copy

SQL provides several functions to work with NULL values effectively. The IFNULL function returns a specified value if the expression is NULL; otherwise, it returns the expression itself. The COALESCE function returns the first non-null value in a list of expressions, making it useful for providing fallback values. The NULLIF function compares two expressions and returns NULL if they are equal; otherwise, it returns the first expression. These functions help you manage missing data and prevent errors in your queries.

123
-- Show each employee's bonus, using 1000.00 as a default if bonus is NULL SELECT name, COALESCE(bonus, 1000.00) AS bonus FROM employees;
copy

1. Which function returns the first non-null value?

2. What does NULLIF do in a query?

3. Fill in the blanks to filter rows where bonus is NULL.

question mark

Which function returns the first non-null value?

Select the correct answer

question mark

What does NULLIF do in a query?

Select the correct answer

question-icon

Fill in the blanks to filter rows where bonus is NULL.

SELECT name FROM employees WHERE bonus ;
Alice Johnson
Bob Smith
Eve Black
Hannah King
Jackie Miller

Click or drag`n`drop items and fill in the blanks

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 5. Kapittel 1
some-alt