MySQL SQRT Function

MySQL SQRT function is one of the Mathematical Functions which returns the square root of any positive expression. In this section, we show you, How to find the square root by using Command Prompt and Workbench with an example.

The basic syntax of the MySQL SQRT Function is

SELECT SQRT (Numeric_Expression)
FROM Source

To demonstrate this Numeric function, we are going to use the below-shown data

Numeric table 1

MySQL SQRT Function Example

The SQRT returns the square root of the positive expression or number. The following square root query shows multiple ways to use the SQRT function.

-- Square Root of Negative Value
SELECT SQRT(-120.00) AS `Square Root Value`;

-- of Positive Value
SELECT SQRT(16) AS `Square Root Value`;

-- of string value
SELECT SQRT('24') AS `Square Root Value`;

-- of a String
SELECT SQRT('MySQL') AS `Square Root Value`;

-- of NULLs
SELECT SQRT('NULL') AS `Square Root Value`;

From the screenshot below, you can see we used SQRT Mathematical Function on different values. Here, we assigned a new name to the MySQL result as ‘Square Root Value’ using the ALIAS Column.

SQRT Example 1

The SQRT also allows you to find square root for the column data. In this example, we are going to find the square root of all the records present in the Standard Cost, Sales, tax Amount, and Service Grade columns.

SELECT Product, Color,
		StandardCost, SQRT(StandardCost) AS Cost, 
        Sales, SQRT(Sales) AS Sales, 
        TaxAmt, SQRT(TaxAmt) AS Tax
FROM `numeric functions`;
MySQL SQRT Example 2