Case clause syntax in MySQL or MariaDB

Example of CASE syntax in MySQL or MariaDB

CASE Statement is like the match condition and returns the value in the Select statement. Once the value matches it will return the value otherwise ELSE value return.

SYNTAX:

CASE match_value
    WHEN match_value1 THEN statement1
    WHEN match_value2 THEN statement2
    ELSE statement_list
END CASE

OR

CASE
    WHEN condition1 THEN statement1
    WHEN condition2 THEN statement2
    ELSE statement3 
END CASE

Example of using CASE statement in MySQL Database:

MariaDB [classicmodels]> 
select 
case when IFNULL(state,'')='' then country 
else state 
end as 'State',
country from offices;

+------------+-----------+
| State      | country   |
+------------+-----------+
| CA         | USA       |
| MA         | USA       |
| NY         | USA       |
| France     | France    |
| Chiyoda-Ku | Japan     |
| Australia  | Australia |
| UK         | UK        |
+------------+-----------+