Operators
In MySQL, operators are symbols used to perform operations on one or more operands.
Following are the types of operators in SQL.
- Arithmetic Operators
- Logical Operators
- Compound Operators
- Comparison Operators
Arithmetic Operators
Arithmetic Operators perform mathematical calculations such as Addition, Subtraction, Multiplication, Module, and Division. The arithmetic operators can be directly used in the SQL statement or combination with column values.
Here are some common arithmetic operators in MySQL:
| Operator | Description | Example | Result |
|---|---|---|---|
+ | Addition | SELECT 5 + 3; | 8 |
- | Subtraction | SELECT 10 - 4; | 6 |
* | Multiplication | SELECT 3 * 7; | 21 |
/ | Division | SELECT 20 / 5; | 4 |
% | Modulus (Remainder) | SELECT 17 % 3; | 2 |
Logical Operators
In MySQL, logical operators combine or compare conditions in a WHERE clause of a SQL query. These operators allow you to create more complex conditions by combining multiple conditions.
Here are some logical operators in MySQL:
| Operator | Description | Example |
|---|---|---|
AND | Logical AND | SELECT * FROM employees WHERE age > 25 AND department = 'Sales'; |
OR | Logical OR | SELECT * FROM employees WHERE age < 25 OR department = 'Marketing'; |
NOT | Logical NOT | SELECT * FROM employees WHERE NOT age = 22; |
Compound Operators
In MySQL, compound operators are shorthand notations that combine an arithmetic or bitwise operation with an assignment. These operators operate and assign the result to a variable in a single step.
Here are some common compound operators in MySQL:
| Operator | Description | Example |
|---|---|---|
+= | Add and assign | SET x = 5; SET x += 3; |
-= | Subtract and assign | SET y = 10; SET y -= 2; |
*= | Multiply and assign | SET z = 3; SET z *= 4; |
/= | Divide and assign | SET w = 20; SET w /= 2; |
Comparison Operators
Comparison operators in MySQL are used to compare values in various conditions within SQL queries. They allow you to create conditions determining which rows should be included in the result set.
Here are some common comparison operators in MySQL:
| Operator | Description | Example |
|---|---|---|
= | Equal to | SELECT * FROM products WHERE Price = 500; |
<> | Not equal to | SELECT * FROM products WHERE Price <> 500; |
< | Less than | SELECT * FROM products WHERE Price < 1000; |
> | Greater than | SELECT * FROM products WHERE Price > 1000; |
<= | Less than or equal to | SELECT * FROM products WHERE Price <= 500; |
>= | Greater than or equal to | SELECT * FROM products WHERE Price >= 500; |
🤖 Don't fully get this? Learn it with Claude
Stuck on Operators? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.
Build the mental picture, not memorization.
I just read a lesson on **Operators** (Databases) and want to truly understand it. Explain Operators from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
Socratic — adapts to where you're stuck.
Teach me **Operators** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
Active recall exposes what you missed.
Quiz me on **Operators** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
Intuition + hook + flashcards for long-term memory.
Help me remember **Operators** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.