SQL ABS()
Published May 29, 2023Updated Jun 11, 2025
Contribute to Docs
The ABS() function in SQL returns the absolute value of a given number. That means, it effectively converts negative numbers to positive numbers, and leaves positive numbers unchanged.
Syntax
SELECT ABS(number)FROM table_name;
Example
In this example, the following data is given in the transactions table:
| temperature_id | temperature |
|---|---|
| 1 | -5.7 |
| 2 | -18.5 |
| 3 | 30.2 |
The ABS() function is used to calculate the absolute temperature value:
SELECT temperature_id, ABS(temperature) AS absolute_tempFROM transactions;
The output will be:
| temperature_id | absolute_temp |
|---|---|
| 1 | 5.7 |
| 2 | 18.5 |
| 3 | 30.2 |
Note:
ABS()is compatible with various SQL database systems such as MySQL, PostgreSQL, Oracle, and SQL Server.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn SQL on Codecademy
- Learn to analyze data with SQL and prepare for technical interviews.
- Includes 9 Courses
- With Certificate
- Beginner Friendly.17 hours
- In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.
- Beginner Friendly.5 hours