SQL queries become powerful when you stop just selecting data and start comparing, filtering, and combining conditions. That is exactly what SQL operators do.
Operators help SQL answer questions like:
- Which customers spent more than ₹5,000?
- Which orders happened this month?
- Which users are active and premium?
- Which products belong to multiple categories?
- Which records are missing values?
If you are learning SQL for data analysis, operators are essential. Because real analysis is not just pulling data. It is filtering the right data.
In this guide, you’ll learn:
- what SQL operators are
- types of SQL operators
- arithmetic operators
- comparison operators
- logical operators
- set operators
- real analyst examples
- common mistakes
- interview questions
This is where SQL starts becoming practical.
What Are SQL Operators?
SQL operators are symbols or keywords used to perform operations on values. They help compare data, combine conditions, and calculate results.
SELECT *
FROM orders
WHERE revenue > 5000;Here: > is an operator. It compares values. Meaning: “Return rows where revenue is greater than 5000.”
Simple idea: Operators help SQL make decisions.
Why SQL Operators Matter for Data Analysts
This is where beginner SQL becomes real-world SQL. Because analyst questions always involve conditions.
Examples:
- Revenue Analysis: Which orders generated more than ₹10,000? Uses:
> - Customer Segmentation: Which users are premium AND active? Uses:
AND - Churn Analysis: Which users have not logged in recently? Uses:
< - Funnel Analysis: Which users completed signup OR trial activation? Uses:
OR
Without operators
You can retrieve data.
With operators
You can analyze data.
Types of SQL Operators
The main operator categories:
- 1. Arithmetic operators
- 2. Comparison operators
- 3. Logical operators
- 4. Set operators
Let’s break them down.
1. Arithmetic Operators in SQL
Arithmetic operators perform mathematical calculations.
| Operator | Meaning |
|---|---|
| + | addition |
| - | subtraction |
| * | multiplication |
| / | division |
| % | modulus (remainder) |
Addition (+)
SELECT price + tax
FROM products;Subtraction (-)
SELECT revenue - discount
FROM orders;Useful for net revenue.
Multiplication (*)
SELECT quantity * unit_price
FROM order_items;Useful for order value calculations.
Division (/)
SELECT revenue / customers
FROM metrics;Use case: Average revenue per customer.
2. Comparison Operators in SQL
Comparison operators compare values. These are used constantly.
- Equal To (=):
WHERE city = 'Mumbai' - Not Equal To (!= or <>):
WHERE city != 'Mumbai' - Greater Than (>):
WHERE revenue > 10000 - Less Than (<):
WHERE stock < 10 - Greater Than or Equal To (>=):
WHERE salary >= 50000 - Less Than or Equal To (<=):
WHERE age <= 25
The Grito Factor One tiny operator mistake can quietly destroy an entire dashboard. Using = instead of >=, or OR instead of AND, can change business numbers massively—without throwing any SQL error. That is why strong analysts double-check logic, not just syntax.
3. Logical Operators in SQL
Logical operators combine multiple conditions. These are core analyst tools.
AND
All conditions must be true.
SELECT *
FROM customers
WHERE city = 'Mumbai'
AND is_premium = TRUE;OR
At least one condition must be true.
SELECT *
FROM customers
WHERE city = 'Mumbai'
OR city = 'Delhi';NOT
Reverses a condition. Cleaner equivalent: WHERE is_active = FALSE.
AND vs OR Example
| city | is_premium |
|---|---|
| Mumbai | TRUE |
| Mumbai | FALSE |
| Delhi | TRUE |
-- Query 1:
WHERE city = 'Mumbai'
AND is_premium = TRUE
-- Returns Only: | Mumbai | TRUE |
-- Query 2:
WHERE city = 'Mumbai'
OR is_premium = TRUE
-- Returns: Multiple rows.4. Set Operators in SQL
Set operators combine the results of multiple queries.
- UNION: Combines rows from two queries. Removes duplicates.
- UNION ALL: Combines rows, keeps duplicates.
- INTERSECT: Returns only rows found in both queries.
- EXCEPT (or MINUS): Returns rows from query 1 that are not in query 2.
Common Beginner Mistakes
1. Confusing AND with OR
This is the #1 mistake. Read logic out loud.
2. Forgetting Parentheses
Bad: WHERE city = 'Delhi' OR city = 'Pune' AND is_active = TRUE
Good: WHERE (city = 'Delhi' OR city = 'Pune') AND is_active = TRUE
3. Using = for NULL
Bad: WHERE status = NULL
Must use IS NULL.
SQL Operators in Interviews
Interviews often test edge cases.
Common questions:
- Difference between UNION and UNION ALL?
- How do you check for NULL values?
- What happens if you use AND and OR without parentheses?
- What does INTERSECT do?
Practice Questions
- Which operator checks if two values are equal?
- Which operator combines conditions where BOTH must be true?
- Which operator combines query results and keeps duplicates?
- Which operator finds the remainder of a division?
What Comes Next?
After operators, learn SQL aliases. Aliases help you name the calculated columns you just created using arithmetic operators.
Final Thoughts
Operators are the building blocks of business logic. Master them, and your SQL becomes incredibly powerful.
Grit Over Excuses.
— The Grito Team