MySQL SQLLesson 42Free preview
MySQL CASE
This lesson is part of MySQL · All levels
Summary
CASE provides the possibility of if-else logic within a MySQL query so we can create the result column conditionally. There are two forms: simple CASE that compares values, and searched CASE that writes the full condition at each WHEN. CASE is very useful for classifying data or display formats without changing the original data.
Key points
- CASE works like an if-else in the SELECT query
- Simple case comparing one value: case column WHEN the value THEN results
- Searched CASE writes full condition: CASE WHEN condition THEN results
- When there is no WHEN filled and without ELSE, the result is
- CASE can also be used in WHERE, ORDER BY, UPDATE, and aggregate functions.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.