This tutorial explains how to use the MySQL LOG function with syntax and examples.
The MySQL LOG function returns either the natural logarithm of a number if called with one parameter, or the logarithm of a number to a specified base if called with two parameters.
The syntax for the LOG function in MySQL is:
LOG( number )
OR
LOG( base, number )
The number to take the natural logarithm of. Must be greater than 0.
The base the natural logarithm is to be calculated with. Must be greater than 1.
The LOG function can be used in the following versions of MySQL:
Let's look at some MySQL LOG function examples and explore how to use the LOG function in MySQL.
For example, let's look at some examples of the LOG function when one parameter is provided:
mysql> SELECT LOG(1);
Output: 0
mysql> SELECT LOG(2);
Output: 0.6931471805599453
mysql> SELECT LOG(2.5);
Output: 0.9162907318741551
mysql> SELECT LOG(0);
Output: NULL
Now let's look at some examples of the LOG function when two parameters are provided:
mysql> SELECT LOG(2, 1);
Output: 0
mysql> SELECT LOG(3, 4);
Output: 1.2618595071429148
mysql> SELECT LOG(2, 0);
Output: NULL
mysql> SELECT LOG(1, 4);
Output: NULL