# SQRT Function in SQL

The SQRT is a SQL function of mathematics which gives the square root of the given number. Suppose, the number is 25, then this function returns 5.

### Syntax of SQRT Function

In the SQRT syntax, we have to pass that number whose square root we want to find.

In the Structured Query Language, we can also use the SQRT function with the fields of the table as shown in the following block:

In this syntax, we have to define the name and column of that table on which we want to perform the SQRT function.

### Examples of SQRT function

Example 1: This example returns the square root of the specified number:

Output:

Squareroot_of_100
10

Example 2: This example returns the square root of the specified number:

Output:

Squareroot_of_2
1.4142135623730

Example 3: This example returns the square root of 8:

Output:

Squareroot_of_8
2.8284

Example 4: This example returns the SQRTary representation of 255:

Output:

Squareroot_of_255
15.968719422671311

Example 5: This example returns the square root of theNULL value:

Output:

Squareroot_of_NULL
-

Example 6: This example returns the square root of numbers from 21 to 30:

Output:

21 22 23 24 25 26 27 28 29 30
45825 4.6904 4.7958 4.8989 5 5.0990 5.1965 5.2915 5.3851 5.4772

Example 7: This example uses the SQRT function with the SQL table.
In this example, we will create the new table through which we will perform the SQRT function on the columns of the table:

The following shows the syntax to create the new table in SQL:

The following CREATE statement creates the Product_Details table for storing the price and quantity of products:

The following multiple INSERT queries insert the records of products with their selling and purchasing price into the Product_Details table:

The following SELECT statement displays the inserted records of the above Product_Details table:

Product_ID Product_Name Product_Quantity Purchasing_Price Selling_Price Release_Date Product_Rating
104 P1 10.250 945 NULL 2022-04-30 NULL
202 P4 15.500 45 75 2022-01-28 5
103 P2 18.250 25 NULL 2022-02-18 4
111 P7 25.250 5 15 2021-12-25 9
210 P6 15.500 50 70 2021-10-15 NULL
212 P8 19.750 110 250 2022-01-28 4
112 P10 10.250 550 835 2022-04-11 NULL

Query 1: The following SELECT query uses the SQRT function with the Product_Quantity column of the above Product_Details table:

This query shows the Square root of product id of each product.

Output:

Product_ID Squareroot_of_Product_ID
104 10.1980
202 14.2126
103 10.1488
111 10.53565
210 14.4913
212 14.56021
112 10.58300

Query 2: The following SELECT query uses the SQRT function with the and Purchasing_Price and Selling_Price column of the above Product_Details table:

This query shows the square root of the purchasing and selling price of each product.

Output:

945 30.7048 NULL -
45 6.70820 75 8.66025
25 5 NULL -
5 2.23606 15 3.872983
50 7.07106 70 8.36660026
110 10.48808 250 15.81138
550 23.4520 835 28.8963

Query 3: The following SELECT query uses the SQRT function with the Product_Rating column of the above Product_Details table:

This query shows the square root of rating of each product in the above table.

Output:

Product_Rating Squareroot_of_productrating
NULL -
5 2.23606
4 2
9 3
NULL -
4 2
NULL -