MySQL SQRT function is one of the Mathematical Function which will return the square root of any positive expression. In this article we will 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 Function is used to return the square root of the positive expression, or number. The following query will show multiple ways to use 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 below screenshot 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 ALIAS Column.
MySQL SQRT Example 2
In 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 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`;
OUTPUT
Thank You for Visiting Our Blog