The POWER() function computes and returns the result of raising a base number to the power of an exponent. It is functionally identical to the POW() function.
Syntax
POWER(x, y)
Definition and Usage
POWER(x, y)calculates xyx^y, wherexis the base, andyis the exponent.- Useful for exponential and mathematical computations in SQL 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, based on the inputs.
Examples
Example 1: Compute 4 raised to the second power
SELECT POWER(4, 2) AS Result;
Output:
Result
------
16
Example 2: Compute 8 raised to the third power
SELECT POWER(8, 3) AS Result;
Output:
Result
------
512
Example 3: Compute a negative base with a positive exponent
SELECT POWER(-3, 4) AS Result;
Output:
Result
------
81
Example 4: Compute a fractional base with a positive exponent
SELECT POWER(1.5, 3) AS Result;
Output:
Result
------
3.375
Example 5: Use with data from a table
If you have a table Calculations with columns Base and Exponent, compute the power for each row:
SELECT Base, Exponent, POWER(Base, Exponent) AS PowerResult
FROM Calculations;
Related Functions
POW(): Identical toPOWER().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 POWER() function is essential for performing exponential calculations in MySQL, and its equivalence to POW() provides flexibility in query writing.