MySQL ABS() Function

Last Updated : 26 Feb 2026

The abs() is a Math function of MySQL. This function is used to get the absolute value of the given number. It is used to return a positive value by removing negative sign of a given number. It is mostly used in:

  • Mathematical calculations
  • Financial analysis

In this article, we will explore the concept of MySQL ABS() function in detail along with its various practical examples.

Syntax

Parameters:

num: It is the number to get absolute value.

Returns

This function returns the absolute value of a number.

Example 1

Explanation: When executing the above query, the abs() function returns the absolute value of the given number.

Output: Following is the output of this example.

MySQL Math ABS() Function

Example 2

Explanation: When executing the above query, the abs() function returns the absolute value of the given number.

Output: Following is the output of this example.

MySQL Math ABS() Function

Example 3

Explanation: When executing the above query, the abs() function returns the absolute value of the given negative number.

Output: Following is the output of this example.

MySQL Math ABS() Function

Example 4

Explanation: On execution of above query, the abs() function returns the absolute value of the given numeric expression in a table column.

Output: The output of this example is given below.

MySQL Math ABS() Function

Example 5

Explanation: On execution of above query, the abs() function returns the absolute value of the given equation.

Output: The output of this example is given below.

MySQL Math ABS() Function

Example 6

Explanation: On execution of above query, the abs() function returns the NULL value, if the value passed is NULL in expression.

Output: The output of this example is given below.

Result
NULL

Using the MySQL ABS() function in a Table column

The MySQL ABS function is used to return the absolute value in a table column.

Follow the steps given below to perform the functionality of MySQL ABS() function in a table's column.

Step 1: Create a table named EMP_INFO with 5 columns such as ID, Name, Department, Salary and Phone using a CREATE TABLE statement.

Step 2: After that INSERT data into an EMP_INFO table using the INSERT TABLE statement.

Step 3: To check the data is inserted or not then use the following SELECT statement.

IDNameDepartmentSalaryPhone
1Anjana GuptaPurchase-30009878453481
2Priyanka SharmaSales40008673193472
3Bobby KapoorMarketing-50008154538525
4Alisha SharmaFinance50009378753481
5Hishant KumarSales-20009718253481
6Ravi MalikMarketing30009874253481
7Sheena KapoorMarketing-50008164538525
8Ravi KumarSales30009873737341

Example:

Explanation: On execution of the above statement, the MySQL ABS() function is used to return the absolute value of the Salary column in a EMP_INFO table.

Output: The output of this example is given below.

IDNameDepartmentSalaryPhone
1Anjana GuptaPurchase30009878453481
2Priyanka SharmaSales40008673193472
3Bobby KapoorMarketing50008154538525
4Alisha SharmaFinance50009378753481
5Hishant KumarSales20009718253481
6Ravi MalikMarketing30009874253481
7Sheena KapoorMarketing50008164538525
8Ravi KumarSales30009873737341

Using MySQL ABS() function in a Table column with WHERE Clause

The MySQL ABS function is used to calculate the absolute values in a table column. With the use of WHERE clause we can restrict the data.

Sample Table: EMP_INFO

IDNameDepartmentSalaryPhone
1Anjana GuptaPurchase-30009878453481
2Priyanka SharmaSales40008673193472
3Bobby KapoorMarketing-50008154538525
4Alisha SharmaFinance50009378753481
5Hishant KumarSales-20009718253481
6Ravi MalikMarketing30009874253481
7Sheena KapoorMarketing-50008164538525
8Ravi KumarSales30009873737341

Example:

Explanation: On execution of the above statement, the MySQL ABS() function is used to return the absolute value of the Salary column in the EMP_INFO table, where the Department column information is 'Marketing'.

Output: The output of this example is given below.

IDNameDepartmentSalaryPhone
3Bobby KapoorMarketing50008154538525
6Ravi MalikMarketing30009874253481
7Sheena KapoorMarketing50008164538525

Next TopicMySQL Math