LOG() Function in SQL

Last Updated : 9 Sep, 2026

The LOG() function in SQL is a mathematical function used to calculate the logarithm of a number. The exact behavior of LOG() can vary between database systems, particularly regarding the logarithm base.m

  • It is useful in mathematical, statistical and financial calculations.
  • The input value must be greater than 0.

Syntax

LOG(number)
  • number: The positive numeric value for which you want to calculate the logarithm.

Note: The LOG() function is supported by MySQL, SQL Server, PostgreSQL, Oracle and SQLite with math functions enabled. The logarithm base and syntax may differ between database systems.

Working

Below are some examples of the LOG() function to understand how it is used with numeric values.

Example 1: Calculate Natural Logarithm

In this example, we will calculate the natural logarithm of 10.

Query:

SELECT LOG(10) AS logarithm_value;

Output:

Screenshot-2026-09-07-180639
  • Calculates the natural logarithm of 10.
  • Returns the result as logarithm_value.

Example 2: Calculate Logarithm with a Specified Base

MySQL allows a second argument to specify the logarithm base.

Query:

SELECT LOG(10, 10) AS logarithm_value;

Output:

Screenshot-2026-09-07-180911
  • Calculates the logarithm of 10 with base 10.
  • Returns 1 because 10¹ = 10.

Example 3: Use LOG() on a Table Column

Let us create a numbers table containing positive numeric values.

Screenshot-2026-09-08-150305

Now, we can use the LOG() function to calculate the natural logarithm of each value.

Query:

SELECT number_id,
value,
LOG(value) AS logarithm_value
FROM numbers;

Output:

Screenshot-2026-09-08-150608
  • Calculates the natural logarithm of each value.
  • Returns the results as logarithm_value.
Comment