MySQL LOG() Function: Calculate natural and custom-base logarithms

LOG(x) returns the natural logarithm of x. MySQL also supports LOG(base, x) for logarithms with a specified base.

LOG(): Quick SQL Example

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
On this page — Show page sectionsHide page sections

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.

Using ROUND() with LOG()

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

Syntax

SELECT LOG(X);
SELECT LOG(B, X);

How to Interpret the Result

LOG() needs a positive argument; an invalid domain produces NULL. With two arguments the base comes first.

Common Question

How is LOG() different from LOG10()?
LOG(x) uses the natural base e; LOG10(x) uses base 10.

↑ Back to top




Subscribe to our YouTube Channel here



plus2net.com




SQL Video Tutorials










✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer