MySQL LN Function

How to use LN function find logarithmic values in MySQL using Command Prompt and Workbench with example?. The LN function is one of the Mathematical Functions, which is useful to return the natural logarithmic value of a given number with base E. The basic syntax of the LN is as shown below:

SELECT LN (x)
FROM Source

If x is less than or equal to 0.0E0, then the function returns the NULL value as output.

MySQL LN Function Example 1

The LN function returns the natural logarithmic value of any numeric value. The next query shows multiple ways to use the LN function.

-- MySQL LN Function Example

SELECT LN(2);

SELECT LN(0);

SELECT LN(-5);

SELECT LN(10);
MySQL LN Function 1

MySQL LN Example 2

The MySQL LN function also allows you to find the logarithmic value of a column data. To demonstrate this LN Mathematical Function, we are going to use the below-shown data

MySQL LN Function 0

In this MySQL example, we are going to find the logarithmic values for all the records present in the ServiceGrade column.

-- MySQL LN Example
SELECT Product, 
		Color, 
        StandardCost, 
        Sales, TaxAmt, 
        ServiceGrade,
        LN(ServiceGrade) AS GradeLog
FROM mysqltutorial.`numeric functions`;

MySQL LN Function 2