MySQL SQRT() Function – Return the Square Root of a Number in MySQL

InĀ MySQL, the SQRT() function returns the square root of a nonnegative number.

You provide the number as an argument when calling the function.

Syntax

The syntax goes like this:

SQRT(X)

Where X is the value for which you’d like the square root returned.

The value must be nonnegative. If it’s negative, the function will return NULL.

Example 1 – Basic Usage

Here’s a basic example to demonstrate.

SELECT SQRT(16);

Result:

+----------+
| SQRT(16) |
+----------+
|        4 |
+----------+

Example 2 – Negative Value

Here’s an example using a negative value.

SELECT SQRT(-16);

Result:

+-----------+
| SQRT(-16) |
+-----------+
|      NULL |
+-----------+

Example 3 – Expressions

You can also use expressions such as this:

SELECT SQRT(10 + 6);

Result:

+--------------+
| SQRT(10 + 6) |
+--------------+
|            4 |
+--------------+