O'Reilly logo

Sams Teach Yourself MySQL by Chris Newman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required