Published May 29, 2023
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.


SELECT ABS(number)
FROM table_name;


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

All contributors

Looking to contribute?

Learn SQL on Codecademy