SQLite 3 reference · Math Functions

SQLite ABS() Function

Return the absolute value of a number, so abs(-7) is 7. NULL gives NULL and text that isn't a number gives 0.0.

SQLite 3

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

abs(X)

Parameters

ParameterDescription
X A number (text that looks like a number is converted).

Return value

A number of the same type, or NULL.

Examples

Absolute valuesTry it yourself
SELECT abs(-7) AS a, abs(3.5) AS b, abs(NULL) AS c;

Output

a | b | c
7 | 3.5 | NULL
Closest to a targetTry it yourself
SELECT name, salary, abs(salary - 120000) AS distance_from_120k
FROM employees
ORDER BY distance_from_120k
LIMIT 3;

Output

name | salary | distance_from_120k
Priya Nair | 115000 | 5000
Lucas Martin | 112000 | 8000
Jonas Berg | 140000 | 20000

In other languages

Was this page helpful?