MySQL LOG Function

MySQL LOG function is one of the Mathematical methods which helps return the natural logarithmic value of a given number. If we specify the base value, then it returns the log value with the base.

This section shows how to find natural logarithmic values in MySQL using Command Prompt and Workbench with natural examples.

The basic syntax of the MySQL LOG function is as shown below:

SELECT LOG(X) FROM Source

SELET LOG(Base, X)

Using this LOG function with a single argument returns the natural logarithmic value of X. And if we use two arguments, the base log value will return.

MySQL LOG Function Example

It returns the natural logarithmic value. The following query will show multiple ways to use the LOG function.

SELECT LOG(1);

SELECT LOG(100);

SELECT LOG(35000);
MySQL LOG Function Example 1

TIP: LOG(2, X) is the same as the LOG2(X) function, and (10, X) is the same as LOG10(X) function.

Here, we are using the base argument. The first MySQL statement returns the base 2 logarithmic value of 10. Within the third statement, LOG(10, 1000) means base 10 Logarithmic value of 10000.

SELECT LOG(2,10);

SELECT LOG(2,1000);

SELECT LOG(2,10000), LOG(10, 10000), LOG(1, 10000);
Logarithm Example 2

The MySQL LOG Function also allows you to find the natural logarithmic value of column data. In this Mathematical method example, we are going to find the natural, base 2, and base 10 logarithmic values for all the records present in the Standard Cost column.

SELECT EnglishProductName,
       Color,
       StandardCost,
       LOG(StandardCost) AS LogStdCost,
       LOG(2, StandardCost) AS Log2StdCost,
       LOG(10, StandardCost) AS Log10StdCost
  FROM `mathemetical functions`;
MySQL LOG Function 3