×

MySQL POWER() function

In this context, we will learn how we can use the MySQL POWER() function with proper syntax and good examples.

Introduction of MySQL POWER() function

The value of a number raised to the power of another number is derived by the POWER function in MySQL. It Returns the value of P raised to the power of Q.

Syntax of the MySQL POWER() function

The syntax of the MySQL POWER() function is given as follows:

POWER(P, Q)

Parameters or arguments used in MySQL POWER() function:

There are two parameters accepted by the POWER() function in MySQL, which are given as follows:

• P: The base number is specified by it.

• Q: The exponent number is specified by it.

Returns:

It will return the value of P raised to the power of Q.

Application used for POWER() function:

The POWER() function can be used in the given below MySQL versions.:

  • MySQL 5.7
  • MySQL 5.6
  • MySQL 5.5
  • MySQL 5.1
  • MySQL 5.0
  • MySQL 4.1
  • MySQL 4.0
  • MySQL 3.23

Examples of MySQL POWER() function:

Now we will look into some MySQL POWER() function examples and will explore how we can use the POWER function in MySQL.

Example-1:

Now we will derive the Power value when both base and exponent are positive using MySQL's POWER() function.

SELECT POWER( 4, 3) AS Power_Value ;

Output:

Power_Value
64
1 row in set (0.00 sec)

Example-2:

Now we will derive the Power value when the base is positive, but the exponent is negative using MySQL's POWER() function.

SELECT POWER( 2, -4) AS Power_Value ;

Output :

Power_Value
0.0625

Example-3:

In this example, we will derive the Power value when the base is negative, but the exponent is positive using the POWER() function in MySQL.

SELECT POWER( -5, 3) AS Power_Value ;

Output :

Power_Value
-125

Example-4:

In this example, we will derive the Power value when both base and exponent are negative using the POWER() function in MySQL.

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

Output :

Power_Value
0.012345679012345678

Example-5:

When we require to find the power value between column data, then we can take the help of the POWER function. To demonstrate, we have created a table named Trigonal.

CREATE TABLE Trigonal(


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

Now we will add some data into the Trigonal table :

INSERT INTO
Trigonal(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 of Trigonal Table –

Select * from Trigonal ;
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 Trigonal;

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

Summary:

In the above context, we have learned how we can use the POWER() function in MySQL used to find the value of a number raised to the power of another number.


Related Topics

MySQL DAY() function

In this context, we will learn how we can use the MySQL DAY() function with proper syntax and good examples. Introduction of MySQL DAY() function This function in MySQL is used to...

2 minutes read.

MySQL CONCAT() function

In this context, we will learn how we can use the MySQL CONCAT() function with proper syntax and good examples. Introduction of MySQL CONCAT() function By using the MySQL CONCAT function, we...

3 minutes read.

MySQL SELF JOIN

This join links table with itself. The inner join, a self join, a right join, and a cross join are connected with two or more two tables. But, the "self...

4 minutes read.

MySQL Stored Procedure

MySQL creates the "stored procedure" function to operate database information. You can use parameters, blocks, and statements to create a new procedure. The procedure requires a database table to use...

3 minutes read.

MySQL CEIL() function

In this context, we will learn how we can use the MySQL CEIL () function with proper syntax and good examples. Introduction of MySQL CEIL() function Input is taken by the CEIL()...

3 minutes read.

MySQL Tutorial

In this tutorial, you will get information about the MySQL management system. This tutorial will cover the basic and advanced level MySQL concepts with examples that will help you become...

5 minutes read.

MySQL function

MySQL function is a piece of program to perform some specific task. Here we pass a parameter and then return a single value. MySQL function mainly supports string, numeric, conditional,...

9 minutes read.

MySQL LOG() function

In this context, we will learn how we can use the MySQL LOG () function with proper syntax and good examples. Introduction of MySQL LOG() function The LOG() function in MySQL is...

3 minutes read.

MySQL Union

MySQL contains the same categories of data in a different table. Sometimes, you require multiple tables to collect data together. MySQL union is a function to combine two table's data...

5 minutes read.

MySQL LENGTH() Function

In this context, we will learn how we can use the MySQL LENGTH() function with proper syntax and good examples. Introduction of MySQL LENGTH() function This function in MySQL is used to...

2 minutes read.

MySQL Table

Introduction MySQL table is an essential part of the system. MySQL table stores data using index, rows, and columns. It accesses data from the server quickly because of the table—this table...

22 minutes read.

MySQL Operators

MySQL Operators MySQL operator needs advanced operation on the table and its data. This operator works with the "WHERE" clause. MySQL operators are a statement to modify information. It helps to...

13 minutes read.

MySQL Features

Features of MySQL MySQL is a relational database management system (RDBMS): It is a collection of many programs and makes relations with many other programs. Easy to use MySQL database: MySQL...

2 minutes read.

MySQL AVG function

This function works on numerical data type values. The average function shows the average value of the data set. If an average function returns a null value, then the row...

5 minutes read.

MySQL MIN function

The MIN() function determines the minimum or lowest value of the data set. This function works on numerical data type values. If the table displays zero value, then the row...

4 minutes read.

MySQL NOW() function

In this context, we will learn how we can use the MySQL NOW() function with proper syntax and good examples. Introduction of MySQL NOW() function Basically, in MySQL, this function is used...

2 minutes read.

MySQL LOG10() function

In this context, we will learn how we can use the MySQL LOG10() function with proper syntax and good examples. Introduction of MySQL LOG10() function To evaluate the natural logarithmic value of...

2 minutes read.

MySQL Database Introduction

MySQL - Database Introduction: The database plays an essential role in MySQL for storing and modifying the data. The database creates and keeps multiple tables. The database organizes and manipulates...

8 minutes read.

MySQL ISNULL function

This function is used to check the null value in table data. It returns the result in a Boolean form. If table data is null, then the output becomes 1....

2 minutes read.

MySQL: Entity-Relationship Model

Entity-Relationship Model Entity-Relationship model or E R model is used to create a relationship between different attributes or entities. It describes the structure of the database with the help of the...

5 minutes read.