Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

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,
Buying_price DECIMAL(13, 2) NOT NULL,
Selling_price DECIMAL(13, 2) NOT NULL,
Service_grade Decimal(6, 2) NOT NULL,
PRIMARY KEY(Product_id)
);

Now inserting some data to the Product table –

INSERT INTO  
Product(Product_name, Buying_price, Selling_price, Service_grade)
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;
PRODUCT_IDPRODUCT_NAMEBUYING_PRICESELLING_PRICESERVICE_GRADE
1Touring Bike2019.003009.65.89
2Mountain Bike3019.504000.5610.00
3Road Bike1019.202000.56-0.89
4Road Bicycle1419.501800.56-1.50
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.

Select Product_id, Product_name, Buying_price, 
Selling_price, Service_grade,
LOG10(Service_grade) AS GRADELOG10  
FROM Product;

Output :

PRODUCT_IDPRODUCT_NAMEBUYING_PRICESELLING_PRICESERVICE_GRADEGRADELOG10
1Touring Bike2019.003009.65.890.7701152947871016
2Mountain Bike3019.504000.5610.001
3Road Bike1019.202000.56-0.89NULL
4Road Bicycle1419.501800.56-1.50NULL
5Racing Bicycle3000.504500.565.000.6989700043360189

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!