Function Reference

LOG

Returns the natural logarithm of a number or its logarithm to the given base.

MySQL 8.4
LOG([base, ]num)
  • [ ]optional part
base
Logarithm base, e by default
DOUBLEOptional
num
Number to take the logarithm of
DOUBLE

Return value

A floating-point number (DOUBLE); NULL if num ≤ 0, base ≤ 0 or base = 1

Examples

Logarithm to base 2

MySQL 8.4
SELECT LOG(2, 8);
LOG(2, 8)
3

Natural logarithm

MySQL 8.4
SELECT LOG(100);
LOG(100)
4.605170185988092

Details

Common bases have their own functions: LN is the natural logarithm, LOG2 and LOG10 use base 2 and 10. Unlike PostgreSQL, where LOG(num) with one argument is the base-10 logarithm, here it is the natural logarithm.

See also

Where to learn