SQL · Reading data

case expression

Returns different values based on conditions. It is an expression, so it can appear in SELECT, WHERE and ORDER BY.

Syntax
case when … then … else … end

Example

Open in the lab

More in this group

and / or / not between coalesce column alias comparison operators distinct distinct on fetch first

Learn this in the course

Reference pages are the quick answer. The course explains the why, shows the full example and ends with a challenge.

Open the course