MySQL: LOG Function

  • Post author:
  • Post category:MySQL
  • Post comments:1 Comment
MySQL LOG Function

In this guide, we will explain how to use the MySQL LOG function with syntax and examples.

Description

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.

Syntax

The syntax for the LOG function in MySQL is:

LOG( number )

OR

LOG( base, number )

Parameters or Arguments

number

The number to take the natural logarithm of. Must be greater than 0.

base

The base the natural logarithm is to be calculated with. Must be greater than 1.

Note

  • The LOG function will return NULL, if number is less than or equal to 0.
  • The LOG function will return NULL, if base is less than or equal to 1.
  • See also the LN and EXP functions.

Applies To

The LOG function can be used in the following versions :

  • MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23

Example

Let’s look at some LOG function examples and explore how to use the LOG function.

For example, let’s look at some examples of the LOG function when one parameter is provided:

mysql> SELECT LOG(1);
Result: 0

mysql> SELECT LOG(2);
Result: 0.6931471805599453

mysql> SELECT LOG(2.5);
Result: 0.9162907318741551

mysql> SELECT LOG(0);
Result: NULL

Now let’s look at some examples of the LOG function when two parameters are provided:

mysql> SELECT LOG(2, 1);
Result: 0

mysql> SELECT LOG(3, 4);
Result: 1.2618595071429148

mysql> SELECT LOG(2, 0);
Result: NULL

mysql> SELECT LOG(1, 4);
Result: NULL

Next Topic : Click Here

This Post Has One Comment

Leave a Reply