Member-only story
Intermediate SQL Topics-Part 5🤝
SQL CASE 💼, SQL NULL 🚫
🔍 What is NULL In SQL? 🚫
NULLrepresents missing, unknown, or not applicable data.- It is not zero, not an empty string, and not false.
- Think of it as a placeholder for “no value”.
📌Why Is It Important to Handle NULL Values?
Handling NULL values is a common task in various real-world scenarios where data may be incomplete or missing. In the realm of databases, NULL values serve as placeholders for uncertain or absent data.
📌Working with NULL in Queries
🔸Testing for NULL
Use IS NULL or IS NOT NULL instead of equality operators:
-- Find users with missing email
SELECT * FROM users
WHERE email IS NULL;
-- Find users with known phone numbers
SELECT * FROM users
WHERE phone_number IS NOT NULL;🔸NULL in Conditional Expressions
SELECT
employee_name,
CASE WHEN
bonus IS NULL THEN 'No bonus'
ELSE
'Has bonus' END AS bonus_status
FROM employees;🔸NULL in Aggregate Functions








