# LOG10() Function in MySQL

• Last Updated : 20 Oct, 2020

LOG10() function in MySQL is used to calculate the natural logarithm of a specific number with base 10. The number must be greater than 0, otherwise it will return NULL.

Syntax :

LOG10(X)

Parameter : This method accepts one parameter as mentioned above in the syntax and described below :

• X – A number whose logarithm value with base 10 we want to calculate. It should be positive number.

Returns : It returns the natural logarithm of given number x with base 10.

Example-1 :
The logarithm of the given number with base 10 using the LOG10() function.

SELECT LOG10(1000) AS Log10_Val ;

Output :

Log10_Val
3

Example-2 :
The logarithm of 0 using LOG10() function.

SELECT LOG10(0) AS Log10_Val ;

Output :

Log10_Val
NULL

Example-3 :
The LOG10 function can also be used to find the logarithmic value with base 10 of a column data. To demonstrate create a table named Product.

CREATE TABLE Product(
Product_id INT AUTO_INCREMENT,
Product_name VARCHAR(100) NOT NULL,
Selling_price DECIMAL(13, 2) NOT NULL,
PRIMARY KEY(Product_id)
);

Now inserting some data to the Product table –

INSERT INTO
VALUES
('Touring Bike', 2019.00, 3009.6, 5.89 ),
('Mountain Bike', 3019.50, 4000.56, 10.00 ),
('Road Bike', 1019.20, 2000.56, -0.89 ),
('Road Bicycle', 1419.50, 1800.56, -1.50 ),
('Racing Bicycle', 3000.50, 4500.56, 5.00) ;

Showing all data in Product Table –

Select * from Product;
1Touring Bike2019.003009.65.89
2Mountain Bike3019.504000.5610.00
5Racing Bicycle3000.504500.565.00

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

FROM Product;

Output :