Related Articles
LOG() Function in MySQL
• Last Updated : 29 Sep, 2020

LOG() function in MySQL is used to calculate the natural logarithm of a specific number. The number must be >0 Otherwise it will return NULL.

Syntax :

```LOG(X)
```

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

• X : A number whose logarithm value we want to calculate. It should be positive number.

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

Example-1 : Logarithm of given number using LOG() function.

```SELECT LOG(5) AS Log_Val ;
```

Output :

Log_Val
1.6094379124341003

Example-2 : Logarithm of 0 using LOG() function.

```SELECT LOG(0) AS Log_Val ;
```

Output :

Log_Val
NULL

Example-3 : The LOG function can also be used to find the logarithmic value of a column data columns. 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, 0.89 ),
('Mountain Bike', 3019.50, 4000.56, 1.00 ),
('Road Bike', 1019.20, 2000.56, -0.89 ),
('Road Bicycle', 1019.50, 1500.56, -1.50 ),
('Racing Bicycle', 3019.50, 4000.56, 2.00) ;
```

So, Our table looks like :

```mysql> Select * from Product;
+------------+----------------+--------------+---------------+---------------+
+------------+----------------+--------------+---------------+---------------+
|          1 | Touring Bike   |      2019.00 |       3009.60 |          0.89 |
|          2 | Mountain Bike  |      3019.50 |       4000.56 |          1.00 |
|          3 | Road Bike      |      1019.20 |       2000.56 |         -0.89 |
|          4 | Road Bicycle   |      1019.50 |       1500.56 |         -1.50 |
|          5 | Racing Bicycle |      3019.50 |       4000.56 |          2.00 |
+------------+----------------+--------------+---------------+---------------+
5 rows in set (0.00 sec)
```

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

```Select Product_id,
Product_name,
Selling_price,
FROM Product;
```

Output :

```+------------+----------------+--------------+---------------+---------------+----------------------+