Home / SQL / Reference / Numbers and NULL

SQL ABS

Return the absolute value (remove the minus sign).

Syntax

ABS(number)

Useful for differences where only the size matters.

Example

Query (on the shop database used in the SQL course)

SELECT name, price, ABS(price - 100) AS distance_from_100
FROM products
ORDER BY distance_from_100
LIMIT 3;

Result

namepricedistance_from_100
Deep Learning (book)89.011.0
Mechanical keyboard119.019.0
Desk lamp59.041.0

3 rows

Related

Learn it step by step in the free lesson Functions: Text, Numbers, Dates & CASE, with exercises that check your queries.