Beginner

335. Simple CASE

Learn how to compare one expression against multiple possible values.

📘 Lesson 335 of 728 ⏱ 10 min 🎯 Beginner

A simple CASE compares one expression with multiple WHEN values and returns the result associated with the first matching value.

Simple CASE is useful when one column contains known categories that need to be converted into more meaningful labels.

Convert department codes into readable department names.

SQL
SELECT
    EmployeeName,
    CASE DepartmentCode
        WHEN 'IT' THEN 'Information Technology'
        WHEN 'HR' THEN 'Human Resources'
        WHEN 'FN' THEN 'Finance'
        ELSE 'Other'
    END AS DepartmentName
FROM Employees;

Simple CASE can be used for category mapping, status labels, reporting classifications, and code translation.

  • Simple CASE compares one expression.
  • Each WHEN provides a possible value.
  • The first matching WHEN is returned.
  • ELSE handles unmatched values.
  • It is useful for category mapping.
What is a simple CASE?

A simple CASE compares one expression against multiple possible values.

When should you use simple CASE?

Use simple CASE when one expression needs to be compared directly with several known values.

Have you finished this lesson?

Introduction to SQL – All Lessons