Back to SQL Notes
Topic #42

SQL Case

CASE works like if-else logic inside a query, letting you map codes to labels or bucket values into ranges. It keeps transformations inside the database instead of the app.


The SQL CASE Expression

The CASE expression is used to define different results based on specified conditions in an SQL statement.

The CASE expression goes through the conditions and stops at the first match (like an if-then-else statement). So, once a condition is true, it will stop processing and return the result. If no conditions are true, it returns the value in the ELSE clause. If there is no ELSE clause and no conditions are true, it returns NULL.

CASE Syntax

CASE

  WHEN condition1 THEN result1

  WHEN condition2 THEN result2

  WHEN conditionN THEN resultN

  ELSE default_result

END;

SQL CASE Example

Here we use the CASE expression to categorize data (Price) and we create a new column (PriceCategory) that shows in which price category each product is:

Example

SELECT ProductName, Price,

CASE

  WHEN Price < 20 THEN 'Low Cost'

  WHEN Price BETWEEN 20 AND 50 THEN 'Medium Cost'

  ELSE 'High Cost'

END AS PriceCategory

FROM Products;

Want to go beyond the notes?

Join Coding Now Tech Institute's SQL course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

SQL Case – FAQs

Quick answers about learning SQL Case in SQL.

This free note from Coding Now Tech Institute explains SQL Case in SQL — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every SQL topic on Coding Now Tech Institute, including SQL Case, is 100% free with no signup required.
With focused practice, most students grasp SQL Case in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now