Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Understanding Null Functions | Null Functions
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
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

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 5. Kapitel 1

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

Suggested prompts:

Can you explain the difference between NULL and an empty string in SQL?

How does the COALESCE function work with multiple columns?

Can you show more examples of handling NULL values in SQL queries?

bookUnderstanding Null Functions

Swipe um das Menü anzuzeigen

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

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 5. Kapitel 1
some-alt