MySQL LOG10() Function: Calculate Base-10 Logarithms
Learn how to use the MySQL `LOG10()` function to calculate the base-10 logarithm of a number. This guide explains the function's purpose, provides clear examples, and highlights the important requirement that input numbers must be greater than zero to avoid errors. Understand how to use `LOG10()` effectively in your MySQL queries.
MySQL LOG10() Function
Definition and Usage
The LOG10()
function in MySQL calculates and returns the base-10 logarithm of a number. In simpler terms, it answers the question: "To what power must I raise 10 to get this number?"
Important Note: The input number must be greater than 0. LOG10()
will return an error if you try to use a non-positive number.
Syntax
Syntax
LOG10(number)
Parameter Values
Parameter | Description |
---|---|
number |
Required. A number greater than 0. |
Examples
Example 1: Logarithm of 2
This example calculates the base-10 logarithm of 2.
SQL Query
SELECT LOG10(2);
Output
LOG10(2)
--------
0.30103
Example 2: Logarithm of 4.5
This example calculates the base-10 logarithm of 4.5.
SQL Query
SELECT LOG10(4.5);
Output
LOG10(4.5)
--------
0.65321
Technical Details
The LOG10()
function is available in MySQL version 4.0 and later.
For natural logarithms (base *e*), see the LOG()
function.