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:
In this article, we will explore the concept of MySQL ABS() function in detail along with its various practical examples.
num: It is the number to get absolute value.
This function returns the absolute value of a number.
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.

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.

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.

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.

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.

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 |
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.
| ID | Name | Department | Salary | Phone |
|---|---|---|---|---|
| 1 | Anjana Gupta | Purchase | -3000 | 9878453481 |
| 2 | Priyanka Sharma | Sales | 4000 | 8673193472 |
| 3 | Bobby Kapoor | Marketing | -5000 | 8154538525 |
| 4 | Alisha Sharma | Finance | 5000 | 9378753481 |
| 5 | Hishant Kumar | Sales | -2000 | 9718253481 |
| 6 | Ravi Malik | Marketing | 3000 | 9874253481 |
| 7 | Sheena Kapoor | Marketing | -5000 | 8164538525 |
| 8 | Ravi Kumar | Sales | 3000 | 9873737341 |
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.
| ID | Name | Department | Salary | Phone |
|---|---|---|---|---|
| 1 | Anjana Gupta | Purchase | 3000 | 9878453481 |
| 2 | Priyanka Sharma | Sales | 4000 | 8673193472 |
| 3 | Bobby Kapoor | Marketing | 5000 | 8154538525 |
| 4 | Alisha Sharma | Finance | 5000 | 9378753481 |
| 5 | Hishant Kumar | Sales | 2000 | 9718253481 |
| 6 | Ravi Malik | Marketing | 3000 | 9874253481 |
| 7 | Sheena Kapoor | Marketing | 5000 | 8164538525 |
| 8 | Ravi Kumar | Sales | 3000 | 9873737341 |
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
| ID | Name | Department | Salary | Phone |
|---|---|---|---|---|
| 1 | Anjana Gupta | Purchase | -3000 | 9878453481 |
| 2 | Priyanka Sharma | Sales | 4000 | 8673193472 |
| 3 | Bobby Kapoor | Marketing | -5000 | 8154538525 |
| 4 | Alisha Sharma | Finance | 5000 | 9378753481 |
| 5 | Hishant Kumar | Sales | -2000 | 9718253481 |
| 6 | Ravi Malik | Marketing | 3000 | 9874253481 |
| 7 | Sheena Kapoor | Marketing | -5000 | 8164538525 |
| 8 | Ravi Kumar | Sales | 3000 | 9873737341 |
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.
| ID | Name | Department | Salary | Phone |
|---|---|---|---|---|
| 3 | Bobby Kapoor | Marketing | 5000 | 8154538525 |
| 6 | Ravi Malik | Marketing | 3000 | 9874253481 |
| 7 | Sheena Kapoor | Marketing | 5000 | 8164538525 |
We request you to subscribe our newsletter for upcoming updates.