DevLearningTools

LEARN · SQL

SQL Operators

An operator is a symbol or keyword that performs an action on one or more values. Learn the three main categories, comparison, logical, and arithmetic, before this module covers each in depth.

The WHERE lesson already used a few operators, = and > among them, without naming the general category. This lesson steps back and covers what an operator actually is, and the three main groups SQL organizes them into, before the rest of this module covers several of them individually in depth.

Learning Objectives

  • Define what an operator is in SQL.
  • Identify the three main categories: comparison, logical, and arithmetic.
  • Know which category a given operator, like AND or >, belongs to.

What Is an Operator?

An operator is a symbol or keyword that performs an action on one or more values or conditions, and produces a result. = compares two values and produces true or false. + adds two numbers and produces a sum. AND combines two conditions and produces a single true/false result. Every operator fits this same shape: input values or conditions in, one result out.

Operator

A symbol or keyword, like = or AND

Applied to Values

Or to other conditions

One Result

A value, or true/false

The Three Main Categories

CategoryPurposeExamples
ComparisonCompare two values, produce true or false=, <>, >, <, >=, <=
LogicalCombine or test conditions, produce true or falseAND, OR, NOT, IN, BETWEEN, LIKE, IS NULL
ArithmeticPerform math on numbers, produce a number+, -, *, /, %

Comparison Operators: A Recap

Already covered in the WHERE lesson: these compare exactly two values and always produce true or false, which is what WHERE needs to decide whether to keep a row.

OperatorMeaning
=equal to
<> or !=not equal to
>greater than
<less than
>=greater than or equal to
<=less than or equal to

Logical Operators: This Module's Focus

Logical operators work on conditions themselves, not just raw values, combining them (AND, OR), reversing them (NOT), or testing a value against a pattern, list, or range (LIKE, IN, BETWEEN). Each of these gets its own full lesson over the rest of this module.

Arithmetic Operators

Standard +, -, *, and / work identically across every database in this course. % (modulo, the remainder of division) is also widely supported, though Oracle uses the function MOD(a, b) instead of the % symbol, worth knowing if you ever need a remainder specifically on Oracle.

MySQL / MariaDB / PostgreSQL / SQLite / SQL Server / Oracle
SELECT first_name, salary, salary * 1.10 AS salary_with_raise
FROM employees;

Try It Yourself

For each of these, name the category it belongs to: >=, AND, *, LIKE.

Answer
>=  -> Comparison
AND -> Logical
*   -> Arithmetic
LIKE -> Logical

Frequently Asked Questions

Is BETWEEN a comparison operator or a logical operator?

Logical. Even though it's checking a range, it's really testing a condition (is this value within these bounds) and producing true or false, the same shape as AND, OR, and the other logical operators, not a direct value-to-value comparison like =.

Are there other operator categories besides these three?

Some databases also have bitwise operators (for manipulating individual bits of a number) and string concatenation operators, both narrower, more specialized categories than the three covered here, and not needed for most day-to-day SQL.

Common Beginner Mistakes

Treating a logical operator like a comparison operator, or vice versa

WHERE salary AND 90000 isn't valid, AND expects two conditions on either side (things that are already true or false), not a column and a raw number. Comparison operators produce the true/false values that logical operators then combine.

Using % for modulo on Oracle and getting a syntax error

Oracle doesn't support the % symbol for modulo, it requires the MOD(a, b) function instead. Every other database in this course accepts %.

Best Practices

  • Know which category an operator falls into, it clarifies what it expects on either side of it.
  • Use MOD(a, b) instead of % when writing arithmetic meant to run on Oracle.
  • Reach for the comparison and logical operators covered in this module before writing a more complex expression or function to achieve the same filtering.

Interview Questions

What's the fundamental difference between a comparison operator and a logical operator?

A comparison operator takes two raw values and produces true or false by comparing them directly, like salary > 90000. A logical operator takes one or more conditions (already true/false results, often from comparison operators) and combines or transforms them, like (salary > 90000) AND (department = 'Engineering').

Why does Oracle require MOD(a, b) instead of a % b for a remainder calculation?

Oracle's SQL implementation never adopted the % symbol as a modulo operator, the function MOD() has always been its equivalent. Every other database in this course (MySQL, MariaDB, PostgreSQL, SQLite, SQL Server) accepts the % symbol directly.

Summary

This lesson covered what an operator is, and the three main categories SQL organizes them into: comparison (produces true/false from two values), logical (combines or transforms conditions), and arithmetic (performs math on numbers).

What's Next?

The next lesson starts this module's tour of logical operators with AND, requiring every condition to be true.

</>

Ready to Practice SQL?

Write and run real SQL queries online, right in your browser, no install or signup required. Pick a playground based on which database you want to practice on.

SQLite / PostgreSQL

Fast, no server, no ads.

Open DB Fiddle ↗

MySQL / SQL Server

Switch databases with one dropdown.

Open SQL Fiddle ↗

Both open a third-party SQL playground in a new tab. External site terms and privacy policy apply.