Knowledge Guide
HomeDatabasesSQL Fundamentals

Operators

In MySQL, operators are symbols used to perform operations on one or more operands.

Following are the types of operators in SQL.

  1. Arithmetic Operators
  2. Logical Operators
  3. Compound Operators
  4. 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:

OperatorDescriptionExampleResult
+AdditionSELECT 5 + 3;8
-SubtractionSELECT 10 - 4;6
*MultiplicationSELECT 3 * 7;21
/DivisionSELECT 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:

OperatorDescriptionExample
ANDLogical ANDSELECT * FROM employees WHERE age > 25 AND department = 'Sales';
ORLogical ORSELECT * FROM employees WHERE age < 25 OR department = 'Marketing';
NOTLogical NOTSELECT * 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:

OperatorDescriptionExample
+=Add and assignSET x = 5; SET x += 3;
-=Subtract and assignSET y = 10; SET y -= 2;
*=Multiply and assignSET z = 3; SET z *= 4;
/=Divide and assignSET 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:

OperatorDescriptionExample
=Equal toSELECT * FROM products WHERE Price = 500;
<>Not equal toSELECT * FROM products WHERE Price <> 500;
<Less thanSELECT * FROM products WHERE Price < 1000;
>Greater thanSELECT * FROM products WHERE Price > 1000;
<=Less than or equal toSELECT * FROM products WHERE Price <= 500;
>=Greater than or equal toSELECT * 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.

🎨 Explain it visually

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.
🤔 Walk me through it (interactive)

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.
🧪 Quiz me & fix my gaps

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.
🧠 Make it stick

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.

📝 My notes