POWER() Function in MySQL

• Last Updated : 01 Oct, 2020

POWER() function in MySQL is used to find the value of a number raised to the power of another number. It Returns the value of X raised to the power of Y.

Syntax :

POWER(X, Y)

Parameter : This method accepts two parameter which are described below :

• X : It specifies the base number.
• Y : It specifies the exponent number.

Returns : It returns the value of X raised to the power of Y.

Example-1 : Finding Power value when both base and exponent is positive using POWER() function.

SELECT POWER( 5, 4) AS Power_Value ;

Output :

Power_Value
625

Example-2 : Finding Power value when base and is positive but exponent is negative using POWER() function.

SELECT POWER( 2, -4) AS Power_Value ;

Output :

Power_Value
0.0625

Example-3 : Finding Power value when base and is negative but exponent is positive using POWER() function.

SELECT POWER( -3, 3) AS Power_Value ;

Output :

Power_Value
-27

Example-4 : Finding Power value when both base and exponent is negative using POWER() function.

SELECT POWER( -3, -4) AS Power_Value ;

Output :

Power_Value
0.012345679012345678

Example-5 : The POWER function can also be used to find the power value between column data. To demonstrate create a table named.

Triangle.

CREATE TABLE Triangle(

Type VARCHAR(25) NOT NULL,
NoOfSides INT NOT NULL,
Base INT NOT NULL,
Height INT NOT NULL
);

Now inserting some data to the Triangle table :

INSERT INTO
Triangle(Type, NoOfSides, Base, Height )
VALUES
('Right-angled Triangle', 3, 4, 3  ),
('Right-angled Triangle', 3, 2, 5  ),
('Right-angled Triangle', 3, 1, 7  ),
('Right-angled Triangle', 3, 7, 9  ),
('Right-angled Triangle', 3, 4, 6  ),
('Right-angled Triangle', 3, 8, 3  ),
('Right-angled Triangle', 3, 10, 10  ) ;

Showing all data in Triangle Table –

Select * from Triangle ;
TypeNoOfSidesBaseHeight
Right-angled Triangle343
Right-angled Triangle325
Right-angled Triangle317
Right-angled Triangle379
Right-angled Triangle346
Right-angled Triangle383
Right-angled Triangle31010

Now, we are going to find the hypotenuse and area for each Right-angled Triangle.

SELECT
*,
sqrt(POWER(Base, 2) + POWER(Height, 2))  AS Hypotenuse,
0.5 * Base * Height as Area
FROM Triangle;

Output :

TypeNoOfSidesBaseHeightHypotenuseArea
Right-angled Triangle34356.0
Right-angled Triangle3255.3851648071345045.0
Right-angled Triangle3177.07106781186547553.5
Right-angled Triangle37911.4017542509913831.5
Right-angled Triangle3467.21110255092797812.0
Right-angled Triangle3838.5440037453175312.0
Right-angled Triangle3101014.14213562373095150.0
My Personal Notes arrow_drop_up