LOG(x) returns the natural logarithm of x. MySQL also supports LOG(base, x) for logarithms with a specified base.
Run this SELECT query directly in MySQL or phpMyAdmin. It uses fixed inputs so you can verify the result without creating a table.
SELECT ROUND(LOG(EXP(1)), 3) AS log_value;| log_value |
|---|
| 1.000 |
With one argument, LOG(X) returns the natural logarithm of X. With two arguments, LOG(B,X) returns the logarithm of X to base B.
SELECT ROUND(LOG(2), 2); -- Output: 0.69
SELECT ROUND(LOG(-2), 2); -- Output: NULL
SELECT ROUND(LOG(6, 3), 2); -- Output: 0.61
For LOG(B,X), X must be greater than 0 and the base B must be greater than 1.
SELECT LOG(6, -0.1); -- Output: NULL
SELECT LOG(-6, 2); -- Output: NULL
SELECT LOG(6, 0.1); -- Output: -1.28509720893847
SELECT LOG(X);SELECT LOG(B, X);
LOG() needs a positive argument; an invalid domain produces NULL. With two arguments the base comes first.
How is LOG() different from LOG10()?
LOG(x) uses the natural base e; LOG10(x) uses base 10.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.