Conditional Functions

MySQL also includes a set of functions that return their result based on a condition, just like the conditions you use in a WHERE clause.

TRUE and FALSE

Every condition returns a value, TRUE or FALSE, depending on whether the condition is satisfied. There is no Boolean data type in MySQL—TRUE equates to 1, and FALSE equates to 0.

You can actually see these values by executing a condition as a query, as follows:

mysql> SELECT code, price, price > 10.00
    -> FROM products;
+------+-------+---------------+
| code | price | price > 10.00 |
+------+-------+---------------+
| MINI | 5.99  |             0 |
| MIDI | 9.99  |             0 |
| MAXI | 15.99 |             1 |
+------+-------+---------------+
3 rows in set (0.00 sec)

The output from this query shows each ...

Get Sams Teach Yourself MySQL now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.