Junior SQL

What is a CASE statement in SQL?

The CASE statement is SQL’s way of handling if-else logic in queries. It allows you to return

different values based on certain conditions.

Example:

SELECT Name,

CASE

WHEN Age < 18 THEN 'Minor'

WHEN Age >= 18 AND Age < 60 THEN 'Adult'

ELSE 'Senior'

END AS AgeGroup

FROM Employees;

More from SQL Server Tutorial

All questions for this course