SQRT() returns the nonnegative square root of a number. It can also be combined with POW() to compute lengths.
Run this SELECT query directly in MySQL or phpMyAdmin. It uses fixed inputs so you can verify the result without creating a table.
SELECT SQRT(81) AS root_value;| root_value |
|---|
| 9 |
SELECT SQRT(16); -- 4
SELECT SQRT(20); -- 4.47213595499958
For a negative argument, SQRT() returns NULL.
SELECT SQRT(-25); -- NULL

H² = A² + B²
H = √(A² + B²)
We will create one UPDATE query by using MySQL pow function.UPDATE sql_sqrt
SET H = SQRT(POW(A, 2) + POW(B, 2));
This will update the table with value of hypotenuse . Here is the PHP code to update the table.
require 'config.php'; // Database connection
$query = 'UPDATE sql_sqrt SET H = SQRT(POW(A, 2) + POW(B, 2))';
$stmt = $dbo->prepare($query);
$stmt->execute();
echo 'Successfully updated H';
SQRT() returns NULL for a negative argument. Existing table-update examples should be tested on sample data first.
What happens with SQRT(-25)?
MySQL returns NULL because a negative real number has no real square root.
UPDATE caution: Run the sample table update only against disposable test data after reviewing affected rows.
Related: EXP()
More related tutorials: All math functions, STDDEV(), AVG()
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.