SQL SQRT() Function
The SQL SQRT() is a function, and returns Double specifying the square root of a non-negative number.
The SQL SQRT() function is supports only numeric column or an numeric field based expression and required number argument is a Double or any valid numeric expression greater than or equal to zero.
It can be used in SELECT statement as well in where clause.
Related Links
SQL SQRT() Syntax
For MySql / Microsoft SQL SERVER
// For Input Number or Expression Value
SELECT SQRT(valid_number);
// For Table Column
SELECT SQRT(Column_name) FROM table_name;
For Microsoft ACCESS
// For Input Number or Expression Value
SELECT SQR(valid_number);
// For Table Column
SELECT SQR(Column_name) FROM table_name;
SQL SQRT() Example - Using Expression Or Formula
The following SQL SELECT statement returns the absolute value of a given input number or expression
SELECT SQRT(4) AS 'Square Root Of 4';
The result of above query is:
Square Root Of 4 |
---|
2 |
SQL SQRT() Function More Example
Input Value | Result |
---|---|
SQRT(9) | 3 |
SQRT(16) | 4 |
SQRT(4.0) | 2 |
SQRT(10) | 3.16227766016838 |
SQRT(1.3) | 1.1401754250991381 |
SQRT(5.675) | 2.382225849914319 |
Sample Database Table - EmpInfo
ID | EmpName | Gender | Age | City |
---|---|---|---|---|
1 | Vidyavathi | Male | 34 | Ramnad |
2 | Harish Karthik | Male | 28 | Mysore |
3 | Nirmala | Female | 32 | Paramakudi |
4 | Varshini Kutty | Male | 26 | Bangalore |
SQL SQRT() Example - With Table Column
The following SQL SELECT statement find the square root of a given table column "ID" and "Age" from the "EmpInfo" table:
For MySql / Microsoft SQL Server
SELECT
ID, SQRT(ID) AS 'Square Root Of ID',
Age, SQRT(Age) AS 'Square Root Of Age'
FROM EmpInfo;
For Microsoft ACCESS
SELECT
ID, SQR(ID) AS 'Square Root Of ID',
Age, SQR(Age) AS 'Square Root Of Age'
FROM EmpInfo;
The result of above query is:
ID | Square Root Of 'ID' | Age | Square Root Of 'Age' |
---|---|---|---|
1 | 1 | 34 | 5.8309518948453 |
2 | 1.4142135623731 | 28 | 5.29150262212918 |
3 | 1.73205080756888 | 32 | 5.65685424949238 |
4 | 2 | 26 | 5.09901951359278 |
SQL SQRT() Example - Using WHERE Clause
The following SQL SELECT statement find the square root value of a given input number for creating condition (less than or equal to the returned square root value) on table column "ID" from the "EmpInfo" table:
SELECT * FROM EmpInfo
WHERE ID <= SQRT(4);
The result of above query is:
ID | EmpName | Gender | Age | City |
---|---|---|---|---|
1 | Vidyavathi | Male | 34 | Ramnad |
2 | Harish Karthik | Male | 28 | Mysore |
Note: The SQRT(4) function will return a value of "2". So now the result set contains and display records or rows which has ID less than or equal to "2" on column "ID" from the "EmpInfo" table.
Related Links