SQL Operators
Get a conceptual overview of the major categories of operators available in SQL, before diving into each category in detail.
Introduction
You have already used several operators without necessarily naming them — the = in a WHERE clause, the > in a HAVING clause, and even the * inside COUNT(*). This lesson takes a step back to give you a clear, organized picture of every major category of operator available in SQL before you dive deeper into each one individually.
Think of this as a map for the next few lessons: once you know the categories that exist, the specific operators covered afterward (logical, comparison, BETWEEN, IN, LIKE) will fit neatly into place.
- What an operator is in the context of SQL.
- The three major categories: arithmetic, comparison, and logical operators.
- A worked example using arithmetic operators inside SELECT.
- A preview of the specialized operators (BETWEEN, IN, LIKE) covered in upcoming lessons.
What is an Operator?
An operator is a symbol or keyword that performs an operation on one or more values and produces a result. In SQL, operators are used everywhere: to do math on numbers, to compare values against each other, and to combine multiple conditions together.
The orders table below will be used for the examples in this lesson.
| id | product | price | quantity |
|---|---|---|---|
| 1 | Keyboard | 45.00 | 2 |
| 2 | Mouse | 20.00 | 3 |
| 3 | Monitor | 150.00 | 1 |
Categories of SQL Operators
SQL operators fall into a small number of broad categories. The table below summarizes the major ones you will use constantly.
| Category | Operators | Purpose |
|---|---|---|
| Arithmetic | + - * / % | Perform mathematical calculations on numeric values. |
| Comparison | = != < > <= >= | Compare two values and produce true, false, or unknown. |
| Logical | AND OR NOT | Combine or negate multiple conditions in WHERE or HAVING. |
Comparison operators are covered in depth in a dedicated lesson soon, and logical operators get their own lesson right after this one — this lesson is just the map, not the full territory.
Arithmetic Operators in Action
Arithmetic operators let you calculate new values directly inside a SELECT statement, without changing anything stored in the table. A common example is calculating a discounted price on the fly.
SELECT product, price, price * 0.90 AS discounted_price
FROM orders;+----------+--------+-------------------+
| product | price | discounted_price |
+----------+--------+-------------------+
| Keyboard | 45.00 | 40.50 |
| Mouse | 20.00 | 18.00 |
| Monitor | 150.00 | 135.00 |
+----------+--------+-------------------+Here, price * 0.90 applies a 10% discount to every row. You can also calculate a total cost by multiplying price by quantity.
SELECT product, price, quantity, price * quantity AS total_cost
FROM orders;+----------+--------+----------+------------+
| product | price | quantity | total_cost |
+----------+--------+----------+------------+
| Keyboard | 45.00 | 2 | 90.00 |
| Mouse | 20.00 | 3 | 60.00 |
| Monitor | 150.00 | 1 | 150.00 |
+----------+--------+----------+------------+The % operator returns the remainder of a division (the modulo), which is useful for things like checking whether a number is even: quantity % 2 = 0.
What is Coming Next
Beyond the three broad categories above, SQL also offers a set of more specialized operators built for specific, very common filtering patterns. Rather than rushing through all of them here, each gets its own focused lesson so you can practice it properly.
Logical Operators
AND, OR, and NOT — combining or negating multiple conditions. Covered in the very next lesson.
Comparison Operators
A closer, dedicated look at =, !=, <, >, <=, >=, including how they behave with NULL.
BETWEEN
A cleaner way to check if a value falls within a range, instead of writing two comparison operators.
IN
Checking if a value matches any one of several listed options, instead of chaining many OR conditions.
LIKE
Pattern matching for text, useful for searching names or descriptions that partially match.
Common Mistakes
- Confusing = (comparison, checks equality) with a single = used for assignment in other programming languages — SQL has no separate assignment operator in a SELECT.
- Forgetting operator precedence: arithmetic operators like * and / are evaluated before + and -, just like in regular math.
- Trying to use + to join text strings in MySQL — MySQL uses the CONCAT() function for that instead, not the + operator.
- Overlooking that dividing two integers can behave differently from dividing a mix of integers and decimals.
Best Practices
- Always alias calculated columns with AS so results are self-explanatory.
- Use parentheses to make the order of arithmetic operations explicit, even when not strictly required.
- Learn the operator categories as a map first, then study each specialized operator (BETWEEN, IN, LIKE) in its own dedicated lesson.
- Reach for the most specific operator available — BETWEEN instead of two comparisons, IN instead of many ORs — once you learn them.
Frequently Asked Questions
Are SQL operators the same across all databases?
The core arithmetic, comparison, and logical operators are essentially identical across MySQL, PostgreSQL, and SQL Server, though a few specialized operators and functions can differ.
Can operators be used outside of WHERE?
Yes. Arithmetic operators are commonly used directly in the SELECT list, as shown in this lesson, while comparison and logical operators are most common in WHERE and HAVING.
What does % do outside of LIKE patterns?
As an arithmetic operator, % returns the remainder of a division (modulo). It has a completely different meaning inside a LIKE pattern, which is covered in its own lesson.
Why learn categories before individual operators?
Seeing the big picture first makes it much easier to remember where each specific operator, like BETWEEN or IN, actually fits and why it exists.
Key Takeaways
- SQL operators fall into three broad categories: arithmetic, comparison, and logical.
- Arithmetic operators (+, -, *, /, %) can calculate new values directly inside a SELECT.
- Comparison and logical operators are most often used inside WHERE and HAVING clauses.
- Specialized operators like BETWEEN, IN, and LIKE build on these basics for specific, common filtering needs.
Summary
SQL operators are the building blocks behind every calculation and every filter condition you write. Arithmetic operators calculate, comparison operators evaluate, and logical operators combine.
In this lesson, you got a conceptual map of the operator categories in SQL and saw arithmetic operators used to calculate a discounted price. Next, you will dive into logical operators — AND, OR, and NOT — in detail.
- You understand the three major categories of SQL operators.
- You can use arithmetic operators inside a SELECT statement.
- You know what BETWEEN, IN, and LIKE are used for, at a high level.
- You are ready to study logical operators in depth.