MySQL POWER() Function
MySQL POWER() Function: Standard SQL Exponentiation
The POWER() function raises a base number x to the exponent y and returns the result as a DOUBLE. It follows the ANSI SQL function name and works identically to MySQL's shorter POW() alias.
Analysts use POWER() in geometric volume calculations, Euclidean distance (SQRT(POWER(dx, 2) + POWER(dy, 2))), and financial discounting formulas. Both integer and decimal arguments are supported.
Syntax
POWER(x, y)
x: Base number.y: Exponent to raisexto.
Practical Example
Suppose demo_products stores shipping crate dimensions (side_cm) for cubic storage containers. You can calculate each crate's internal cubic volume in liters using POWER(side_cm, 3) / 1000.
SELECT
product_id,
product_name,
side_cm,
ROUND(POWER(side_cm, 3) / 1000, 2) AS volume_liters
FROM demo_products
WHERE side_cm IS NOT NULL;
| product_id | product_name | side_cm | volume_liters |
|---|---|---|---|
| 91 | Small Cube Box | 20.0 | 8.00 |
| 92 | Medium Cube Box | 35.0 | 42.88 |
| 93 | Large Crate | 50.0 | 125.00 |
Cube 92 has 35^3 = 42875 cubic centimeters, which divides by 1000 cleanly to 42.88 liters.
Common Mistakes & NULL Behavior
- Mistaking ^ for POWER(): Many spreadsheets use
^for powers, whereas MySQL treats^as bitwiseXOR. Writingside_cm ^ 3returns completely wrong integer bits instead of cubingside_cm. - Zero to a negative power:
POWER(0, -2)attempts1 / 0, triggering an out-of-range error in MySQL. Protect zero bases withNULLIF(base, 0)when exponents can be negative. - NULL propagation: Passing
NULLas either the base or exponent returnsNULL.
Frequently Asked Questions
Should I write POW() or POWER() in MySQL queries?
Both perform identically in MySQL. Choose POWER() if you want queries that match PostgreSQL, SQL Server, and Oracle SQL syntax without edits.
How can I compute a cube root with POWER()?
Pass 1 / 3 as the exponent: POWER(27, 1 / 3) returns 3. Make sure x >= 0 to avoid invalid domain roots on negative numbers.
Unlock Your
Full Potential.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Try it Yourself
Experiment with the code from this lesson in our interactive playground.