Example of SELECT with CASE or IF syntax in MySQL
Example of using CASE with SELECT statement
SELECT name, population,
CASE WHEN population >= 1000000 THEN 'Over' ELSE 'Below' END AS 'Status Population'
FROM city limit 5;
+----------------+------------+-------------------+
| name | population | Status Population |
+----------------+------------+-------------------+
| Kabul | 1780000 | Over |
| Qandahar | 237500 | Below |
| Herat | 186800 | Below |
| Mazar-e-Sharif | 127800 | Below |
| Amsterdam | 731200 | Below |
+----------------+------------+-------------------+
5 rows in set (0.00 sec)
Example of using IF with SELECT statement
SELECT name, population,
IF( population >= 1000000, 'Over', 'Below') AS 'Status Population'
FROM City limit 5;
+----------------+------------+-------------------+
| name | population | Status Population |
+----------------+------------+-------------------+
| Kabul | 1780000 | Over |
| Qandahar | 237500 | Below |
| Herat | 186800 | Below |
| Mazar-e-Sharif | 127800 | Below |
| Amsterdam | 731200 | Below |
+----------------+------------+-------------------+
5 rows in set (0.00 sec)