MySQL POW() Function

The POW() function calculates and returns the result of a base number raised to the power of an exponent.


Syntax

POW(x, y)

Definition and Usage

  • POW(x, y) computes xyx^y, where x is the base, and y is the exponent.
  • The function is equivalent to the POWER() function.
  • Commonly used for exponential calculations in mathematical queries.

Parameter Values

Parameter Description
x Required. The base number
y Required. The exponent to raise x

Technical Details

  • Introduced in: MySQL 4.0
  • Return Value: A floating-point or integer number, depending on the input.

Examples

Example 1: Compute 4 raised to the second power

SELECT POW(4, 2) AS Result;

Output:

Result
------
16

Example 2: Compute 8 raised to the third power

SELECT POW(8, 3) AS Result;

Output:

Result
------
512

Example 3: Compute a negative base with a positive exponent

SELECT POW(-2, 3) AS Result;

Output:

Result
------
-8

Example 4: Compute a fractional base with a positive exponent

SELECT POW(2.5, 2) AS Result;

Output:

Result
------
6.25

Example 5: Use with columns in a table

If you have a table Numbers with columns Base and Exponent, calculate the power for each row:

SELECT Base, Exponent, POW(Base, Exponent) AS PowerResult
FROM Numbers;

Related Functions

  • POWER(): Identical to POW().
  • EXP(): Returns exe^x, where ee is the base of natural logarithms.
  • LOG(): Returns the logarithm of a number.
  • SQRT(): Returns the square root of a number.

The POW() function is versatile and widely used for mathematical calculations in MySQL queries.


Was this article helpful?