Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Understanding Null Functions | Section
Essential SQL Functions for Data Cleaning and Transformation

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?

正しい答えを選んでください

question mark

What does NULLIF do in a query?

正しい答えを選んでください

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

クリックまたはドラッグ`n`ドロップして空欄を埋めてください

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 1.  25

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 1.  25
some-alt