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 in using Command Prompt and Workbench with an example.

The basic syntax of the SQRT in MySQL is

SELECT SQRT (Numeric_Expression)
FROM Source

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

MySQL SQRT Function 1

MySQL SQRT Function Example

The MySQL 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`;

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

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

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

-- Square Root 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.

MySQL 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 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