MySQL SQRT function is one of the Mathematical Function which returns the square root of any positive expression. In this section, we show you, How to find the square root in MySQL using Command Prompt and Workbench with example.
MySQL SQRT Syntax
The basic syntax of the SQRT in MySQL is as shown below:
SELECT SQRT (Numeric_Expression) FROM Source
To demonstrate this MySQL SQRT Numeric function, we are going to use the below shown data
MySQL SQRT Function Example 1
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.
-- MySQL SQRT Function Example -- 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 MySQL SQRT function on different values. Here, we assigned a new name to the result as ‘Square Root Value’ using the ALIAS Column.
MySQL SQRT Example 2
The MySQL 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.
-- MySQL SQRT Function Example USE mysqltutorial; SELECT Product, Color, StandardCost, SQRT(StandardCost) AS Cost, Sales, SQRT(Sales) AS Sales, TaxAmt, SQRT(TaxAmt) AS Tax FROM `numeric functions`;