MySQL SQRT() Function

The SQRT() function in MySQL is used to return the square root of a given number.


Definition and Usage

  • The SQRT() function returns the square root of a number.
  • The number must be greater than or equal to 0; otherwise, the function will return NULL.

Syntax

SQRT(number)

Parameter Values

Parameter Description
number A number for which the square root is to be calculated. The value must be greater than or equal to 0.

Technical Details

  • Works in: From MySQL 4.0
  • Return Value: A floating-point number representing the square root of the given number.

Examples

Example 1: Square root of 64

SELECT SQRT(64);

Output:

8

Example 2: Square root of 13

SELECT SQRT(13);

Output (approximately):

3.605551275463989

Example 3: Square root of 0

SELECT SQRT(0);

Output:

0

Example 4: Square root of a negative number (returns NULL)

SELECT SQRT(-25);

Output:

NULL

Use Cases

  • Used in mathematical calculations, such as finding the distance in geometry (Pythagorean theorem).
  • Applied in statistics and physics for calculations like standard deviation and energy in certain formulas.

Related Functions

  • POW() or POWER(): Returns a number raised to the power of another number.
  • EXP(): Returns e raised to the power of a specified number (exponential function).
  • LOG() or LN(): Returns the logarithm of a number.

Was this article helpful?