MySQL LOG() Function

In MySQL, the LOG() function returns the logarithm of the specified number to the specified base.

LOG() Syntax

Here is the syntax of MySQL LOG() function:

LOG(number)
LOG(base, number)

LOG(number) A function is equivalent to a LN(number) function.

Parameters

number
Required. A number whose value must be greater than 0.
base
Optional. The base whose value must be greater than 1.

Return value

In MySQL, the LOG() function returns the logarithm of the specified number to the specified base.

  • If number is less than or equal to 0, the LOG() function will return NULL.
  • If base is less than or equal to 1, the LOG() function will return NULL.
  • The LOG() function will return NULL if any parameter is NULL.

LOG() Examples

SELECT
    LOG(1),
    LOG(EXP(1), 1),
    LOG(2),
    LOG(EXP(1), 2),
    LOG(2, 16),
    LOG(10, 100),
    LOG(0),
    LOG(-1),
    LOG(1, 10),
    LOG(NULL)\G

output

        LOG(1): 0
LOG(EXP(1), 1): 0
        LOG(2): 0.6931471805599453
LOG(EXP(1), 2): 0.6931471805599453
    LOG(2, 16): 4
  LOG(10, 100): 2
        LOG(0): NULL
       LOG(-1): NULL
    LOG(1, 10): NULL
     LOG(NULL): NULL