Home › coding › sql › sql case

Sql Case — Free Sql Tutorial

Learn Sql Case in Sql with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.

✓ 100% Free ✓ No Login Needed ✓ NCERT / CBSE Aligned ✓ Download as PDF

TL;DR: Learn Sql Case in Sql with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.

Written & reviewed by the Syllab.in Academic Team (CBSE/NCERT subject experts) · Updated Jul 14, 2026

🤖 Stuck on any question? Ask Syllab's free AI Tutor for a step-by-step explanation — instant, unlimited, no login.

Sql Case in Sql

The CASE expression adds if/else logic to SQL queries. It lets you transform or categorise data on the fly without needing to create a separate column or table.

CASE WHEN condition THEN result ELSE default END is the general form. You can have multiple WHEN clauses. The ELSE is optional (returns NULL if no WHEN matches and ELSE is absent).

Use CASE for: Grade assignment (85+ = A, 70+ = B, etc.), Categorising products by price range, Converting codes to labels (1='Male', 2='Female'), Custom sorting orders, Computing different values based on conditions.

Sql Case — Syntax

-- Simple CASE (like switch):
CASE column
  WHEN value1 THEN result1
  WHEN value2 THEN result2
  ELSE default_result
END

-- Searched CASE (like if/elif/else):
CASE
  WHEN marks >= 90 THEN 'A+'
  WHEN marks >= 80 THEN 'A'
  WHEN marks >= 40 THEN 'Pass'
  ELSE 'Fail'
END

Learn Sql Case step by step with Syllab's free interactive Sql tutorial — runnable code examples, practice exercises and instant AI feedback, all free with no signup. Explore the full Sql course →

Explore:

  • Syllabus
  • Practice
  • Mock Tests
  • NCERT Solutions
  • Coding
  • GK Quiz
  • Career Predictor
  • AI Tutor
  • Live Quiz
  • Doubt Solver
  • Microlearning
  • Free Alternatives
  • Kids Zone
  • Study Room
  • Calculators
  • Worksheets

Syllab.in — Free learning for Indian students, Class 1–12