Beginner

378. Simple CASE

Learn how to compare one expression against multiple possible values using simple CASE.

📘 Lesson 378 of 728 ⏱ 10 min 🎯 Intermediate

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

Simple CASE is useful when a single column needs to be mapped into readable labels or categories.

Convert department codes into department names.

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

It is useful for status mapping, code translation, category labeling, and report-friendly descriptions.

  • Simple CASE compares one expression.
  • Each WHEN contains a value to compare.
  • THEN provides the matching result.
  • ELSE handles unmatched values.
  • END closes the CASE expression.
What is a simple CASE?

A simple CASE compares one expression against multiple specified values.

When should simple CASE be used?

It is useful when one expression needs to be mapped against several known values.

Have you finished this lesson?

Introduction to SQL – All Lessons