SQL CASE Statement - Conditional Logic Inside Queries

Introduction

Imagine you’re preparing a report card, and you want to assign grades based on marks. You need conditional logic — something like “if marks > 90, then grade is A.” In SQL, this kind of logic is handled beautifully using the CASE statement.

What is the CASE Statement?

The CASE statement allows you to add IF-ELSE type logic inside your SELECT queries. It evaluates conditions and returns values based on the first condition that is true.

Syntax