×

MySQL LN() function

In this context, we will learn how we can use the MySQL LN() function with proper syntax and good examples.

Introduction of MySQL LN() function

For evaluation of the natural logarithm of a mentioned number with base e, the LN() function in MySQL is used. It will return NULL when the number is greater than 0.

Syntax of the MySQL LN() function

The syntax of the MySQL LN() function is given as follows:

LN(Y);

Parameters or arguments used in MySQL LN() function:

Only one parameter is accepted by LN() function, as mentioned above in the syntax and described below as follows.

Y: This is the number whose logarithm value with base e we want to calculate. It should be a positive number.

Returns: It will return the natural logarithm of the given number Y with base e.

The application used for LN() function:

The LN() function can be used in the given below MySQL versions:

  • MySQL 5.7
  • MySQL 5.6
  • MySQL 5.5
  • MySQL 5.1
  • MySQL 5.0
  • MySQL 4.1
  • MySQL 4.0
  • MySQL 3.23

Examples of MySQL LN() function:

Now, we will look into some examples of MySQL LN functions.

Example 1:

Here, we will find the logarithm of the given numbers with base e using the LN() function in MySQL.

SELECT LN(1000) AS Ln_Val ;

Output:

LN_VAL
6.907755278982137
1 row in set (0.00 sec)

Example 2:

Here, we will find the logarithm of 0 with base e using the LN() function in MySQL.

SELECT LN(0) AS Ln_Val ;

Output:

LN_VAL
NULL
1 row in set (0.00 sec)

Example 3:

The LN function can also be used to find the logarithmic value with base e of column data. To demonstrate, create a table named Commodity.

CREATE TABLE Commodity(
Commodity_id INT AUTO_INCREMENT,  
Commodity_name VARCHAR(100) NOT NULL,
Purchasing_price DECIMAL(13, 2) NOT NULL,
Selling_price DECIMAL(13, 2) NOT NULL,
Service_grade Decimal(6, 2) NOT NULL,
PRIMARY KEY(Commodity_id)
);

Inserting into the Commodity table:

Now we will add some data to the Commodity table –

INSERT INTO  
Commodity(Commodity_name, Purchasing_price, Selling_price, Service_grade)
VALUES
('Touring Bike,' 20000.00, 30050.00, 4.17 ),
('Mountain Bike,' 30005.50, 40000.56, 10.00 ),
('Road Bike,' 10000.20, 21000.56, -3.59 ),
('Road Bicycle,' 15200.50, 18000.00, -0.50 ),
('Racing Bicycle,' 30500.50, 45000.00, 3.00) ;

Reading data from the table :

Now we will Show all data in Commodity Table –

Select * from Commodity;

Output:

COMMODITY_IDCOMMODITY_NAMEPURCHASING_PRICESELLING_PRICESERVICE_GRADE
1Touring Bike20000.0030050.004.17
2Mountain Bike30005.5040000.5610.00
3Road Bike10000.2021000.56-3.59
4Road Bicycle15200.5018000.00-0.50
5Racing Bicycle30500.5045000.00 3.00

Now, we are going to find the logarithmic values with base e for all the records present in the Service_grade column.

Select Commodity_id, Commodity_name, Purchasing_price,  
Selling_price, Service_grade,
LN(Service_grade) AS GRADELOGN  
FROM Commodity;

Output:

COMMODITY_IDCOMMODITY_NAMEPURCHASING_PRICESELLING_PRICESERVICE_GRADEGRADELOGN
1Touring Bike20000.0030050.004.171.4279160358107101
2Mountain Bike30005.5040000.5610.002.302585092994046
3Road Bike10000.2021000.56-3.59NULL
4Road Bicycle15200.5018000.00-0.50NULL
5Racing Bicycle30500.5045000.00  

Summary:

In this context, we have learned how we can use the MySQL LN() function to find the LN values from given arguments respectively.


Related Topics

MySQL LENGTH() Function

In this context, we will learn how we can use the MySQL LENGTH() function with proper syntax and good examples. Introduction of MySQL LENGTH() function This function in MySQL is used to...

2 minutes read.

MySQL Clauses

MySQL Clauses MySQL system clauses are keywords or statements to handle information. It helps to operate a group of the data and apply it to require conditions. The clauses apply conditions...

16 minutes read.

MySQL MIN function

The MIN() function determines the minimum or lowest value of the data set. This function works on numerical data type values. If the table displays zero value, then the row...

4 minutes read.

MySQL LIKE() function

In this context, we will learn how we can use the MySQL LIKE() function with proper syntax and good examples. Introduction of MySQL LIKE() function The LIKE function is a logical function...

4 minutes read.

MySQL QUARTER() function

In this context, we will learn how we can use the MySQL QUARTER() function with proper syntax and good examples. Introduction of MySQL QUARTER() function The QUARTER() function in MySQL returns the...

3 minutes read.

MySQL MOD() function

In this context, we will learn how we can use the MySQL MOD() function with proper syntax and good examples. Introduction of MySQL MOD() function Basically, in MySQL, the MOD() function is...

3 minutes read.

MySQL database queries

MySQL database queries Database queries help to create, use, show and, delete the database. A Database is a collection of several tables and data. The database uses SQL language to perform...

3 minutes read.

MySQL SELF JOIN

This join links table with itself. The inner join, a self join, a right join, and a cross join are connected with two or more two tables. But, the "self...

4 minutes read.

MySQL FIELD() function

In this context, we will learn how we can use the MySQL FIELD() function with proper syntax and good examples. Introduction of MySQL FIELD() function The index position of a mentioned value...

3 minutes read.

Clustered vs Non-Clustered Index

Clustered vs. Non-Clustered Index The difference between clustered and non-clustered index is the most famous question in the database-related interviews. Both indexes have the same physical structure and are stored as...

2 minutes read.

MySQL Error 1046 - No Database Selected

What is MySQL? MySQL is a Relational Database Management System (RDBMS). SQL in MySQL is the abbreviation of "Structured Query Language", which Oracle developed it in 1995. It is one of...

1 minute read.

MySQL PERIOD_ADD() function

In this context, we will learn how we can use the MySQL PERIOD_ADD() function with proper syntax and good examples. Introduction of MySQL PERIOD_ADD() function In MySQL, PERIOD_ADD() function will help to...

2 minutes read.

MySQL AVG function

This function works on numerical data type values. The average function shows the average value of the data set. If an average function returns a null value, then the row...

5 minutes read.

MySQL Union

MySQL contains the same categories of data in a different table. Sometimes, you require multiple tables to collect data together. MySQL union is a function to combine two table's data...

5 minutes read.

MySQL Constraints

MySQL Constraints Introduction The constraints help to restrict what values should be stored in a table. The constraints provide limitations of the columns or data. This function helps to insert data in...

20 minutes read.

MySQL SEC_TO_TIME() function

In this context, we will learn how we can use the MySQL SEC_TO_TIME() function with proper syntax and good examples. Introduction of MySQL SEC_TO_TIME() function This function in MySQL is used to...

2 minutes read.

MySQL LOG() function

In this context, we will learn how we can use the MySQL LOG () function with proper syntax and good examples. Introduction of MySQL LOG() function The LOG() function in MySQL is...

3 minutes read.

MySQL RIGHT JOIN

MySQL right join links two tables with each other. The left table column connects with the complete right side table. Each row of the right table tries to connect with...

4 minutes read.

MySQL Features

Features of MySQL MySQL is a relational database management system (RDBMS): It is a collection of many programs and makes relations with many other programs. Easy to use MySQL database: MySQL...

2 minutes read.

MySQL INSTR() Function

In this context, we will learn how we can use the MySQL INSTR() function with proper syntax and good examples. Introduction of MySQL INSTR() function This function in MySQL returns the location...

4 minutes read.