SQL Operators Reference

Updated · 4 min read

Operators combine values: they add, compare, match patterns and join conditions. This page lists the common ones with a real example each, and the precedence table that decides which operator is applied first. For explanations, see SQL Operators and AND, OR and NOT.

Arithmetic Operators

OperatorMeaningExampleResult
+Add2 + 35
-Subtract7 - 25
*Multiply4 * 312
/Divide (integers give an integer in PostgreSQL)7 / 23
%Remainder7 % 21
^Power (PostgreSQL)2 ^ 101024

Comparison Operators

OperatorMeaningExampleResult
=Equal1 = 1true
<> or !=Not equal1 <> 2true
<, >, <=, >=Less, greater2 >= 2true
IS DISTINCT FROMNot equal, treating NULLs as comparableNULL IS DISTINCT FROM 1true

Logical Operators

OperatorMeaningExampleResult
ANDBoth truetrue AND falsefalse
ORAt least one truetrue OR falsetrue
NOTNegateNOT truefalse

Pattern and Range Operators

OperatorMeaningExampleResult
LIKEPattern with % and _'Navika' LIKE 'Nav%'true
ILIKECase-insensitive LIKE (PostgreSQL)'Navika' ILIKE 'nav%'true
BETWEENInclusive range5 BETWEEN 1 AND 5true
INIn a list'CA' IN ('CA', 'TX')true
~Regular expression match (PostgreSQL)'2025-12-03' ~ '^\d{4}'true

Text Operators

OperatorMeaningExampleResult
||Join text'Nav' || 'ika'Navika

Sets and Subqueries Operators

OperatorMeaningExampleResult
EXISTSSubquery returns a rowEXISTS (SELECT 1)true
ANY / SOMETrue for at least one value3 > ANY (ARRAY[1, 5])true
ALLTrue for every value3 > ALL (ARRAY[1, 5])false

Check the Examples

Every result in the tables above comes from this query:

SQL▶ Try it
SELECT 2 + 3 AS c1,
       7 - 2 AS c2,
       4 * 3 AS c3,
       7 / 2 AS c4,
       7 % 2 AS c5,
       2 ^ 10 AS c6,
       1 = 1 AS c7,
       1 <> 2 AS c8,
       2 >= 2 AS c9,
       NULL IS DISTINCT FROM 1 AS c10,
       true AND false AS c11,
       true OR false AS c12,
       NOT true AS c13,
       'Navika' LIKE 'Nav%' AS c14,
       'Navika' ILIKE 'nav%' AS c15,
       5 BETWEEN 1 AND 5 AS c16,
       'CA' IN ('CA', 'TX') AS c17,
       '2025-12-03' ~ '^\d{4}' AS c18,
       'Nav' || 'ika' AS c19,
       EXISTS (SELECT 1) AS c20,
       3 > ANY (ARRAY[1, 5]) AS c21,
       3 > ALL (ARRAY[1, 5]) AS c22;
Output
 c1 | c2 | c3 | c4 | c5 |  c6  | c7 | c8 | c9 | c10 | c11 | c12 | c13 | c14 | c15 | c16 | c17 | c18 |  c19   | c20 | c21 | c22
----+----+----+----+----+------+----+----+----+-----+-----+-----+-----+-----+-----+-----+-----+-----+--------+-----+-----+-----
  5 |  5 | 12 |  3 |  1 | 1024 | t  | t  | t  | t   | f   | t   | f   | t   | t   | t   | t   | t   | Navika | t   | t   | f
(1 row)

Precedence

Operators higher in this list are applied first (PostgreSQL's order; other databases are very similar). When in doubt, use parentheses: they make the intent clear to readers too.

OrderOperatorNotes
1.Table and column separator
2::PostgreSQL type cast
3[ ]Array element
4unary + -Sign
5^Power
6* / %Multiply, divide, remainder
7+ -Add, subtract
8other operatorsIncluding `
9BETWEEN IN LIKE ILIKE SIMILARRange and pattern tests
10< > = <= >= <>Comparison
11IS ISNULL NOTNULLIS TRUE, IS NULL, IS DISTINCT FROM ...
12NOTLogical negation
13ANDLogical and
14ORLogical or

Was this tutorial helpful?