×

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 LN() function

In this context, we will learn how we can use the MySQL LN() function with proper syntax and good examples. Introduction of MySQL LN() function For evaluation of the natural logarithm 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.

find_in_set() function in MySQL

This Function is used for finding the position of a particular string from the list of strings. For suppose if the specified string is repeated multiple times, then this functions...

4 minutes read.

MySQL CEILING() function

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

2 minutes read.

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...

3 minutes read.

MySQL Math Function

The math function operates numerical values and displays required number data. The math function finds out sin, cos, tan values. Here, you find out the absolute value, reminder, and logarithmic...

6 minutes read.

MySQL Date and Time function

The date function displays day, year, month, time, and current date. It shows the date and time as per the requirement of the applications. The data either store on the...

8 minutes read.

MySQL logical conditions

MySQL logical conditions Introduction MySQL handles data with clauses, operators, and conditions. The logical condition is used to compare information and returns the required output. This condition applies logic to MySQL expressions...

7 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 Triggers

MySQL trigger is a function of the stored procedure to respond to the system program. This function responds and runs any data table event automatically. You can use it for...

5 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 Show index

This query helps to access and retrieve table information. This syntax displays the required index or all indexes of the table. It also displays the index type as per the...

3 minutes read.

MySQL LOCATE() function

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

3 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 Queries

MySQL Queries MySQL supports SQL queries in the MySQL interface. These queries help to interact data with the application. MySQL uses create database, user database, create a table, truncate table, and...

13 minutes read.

MySQL FLOOR() function

In this context, we will learn how we can use the MySQL FLOOR() function with proper syntaxes and examples. Introduction of MySQL Floor() function: FLOOR() function in MySQL is used to return...

3 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 Descending Index

Descending Index It is a type of index that stores key values in descending order. This query improves the performance of an index query. MySQL system displays the index as per...

3 minutes read.

MySQL Command line client Basic Queries

MySQL – command line client Basic Queries There are many queries to work with the MySQL command-line client. Today, we will explore MySQL basic queries and their function. The MySQL query...

8 minutes read.

MySQL INSERT() Function

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

2 minutes read.