Skip to main content

SQL Operators 🧮

Mentor's Note: Operators are the verbs of your query logic. They define how you want to filter, calculate, or compare your data. Without them, you can only fetch raw lists. 💡


🌟 The Scenario: The Online Store 🛒

Imagine you run an e-commerce site. You need to filter products.

  1. Arithmetic: "Calculate the price after a 10% discount." (Price * 0.9)
  2. Comparison: "Show products cheaper than ₹500." (Price < 500)
  3. Logical: "Show items that are Red AND Large." (Color = 'Red' AND Size = 'L')

🎨 Visual Logic: Operator Types


💻 1. Arithmetic Operators (Math) ➕

Used to perform mathematical operations on numeric data.

OperatorDescriptionExampleResult
+AddSELECT 10 + 5;15
-SubtractSELECT 10 - 5;5
*MultiplySELECT 10 * 5;50
/DivideSELECT 10 / 5;2
%Modulus (Remainder)SELECT 10 % 3;1
-- Scenario: Calculate Annual Salary
SELECT salary * 12 AS annual_salary FROM employees;

💻 2. Comparison Operators (Testing) ⚖️

Used to compare two values. Returns TRUE or FALSE.

OperatorDescriptionExample
=Equal toWHERE salary = 50000
<> or !=Not equal toWHERE dept <> 'HR'
>Greater thanWHERE age > 18
<Less thanWHERE price < 100
>=Greater than or equalWHERE rating >= 4.5
<=Less than or equalWHERE stock <= 10
-- Scenario: Find High Value Products
SELECT * FROM products WHERE price > 1000;

💻 3. Logical Operators (Combiners) 🔗

Used to combine multiple conditions.

OperatorDescriptionLogic
ANDTRUE if all conditions are TRUERed AND Large (Must be both)
ORTRUE if any condition is TRUERed OR Blue (Can be either)
NOTReverses the resultNOT Red (Anything but Red)
-- Scenario: Find specific shoes
SELECT * FROM shoes
WHERE (color = 'Black' OR color = 'Brown')
AND size = 10;

💡 Operator Precedence (BODMAS for SQL)

When combining operators, SQL follows a strict order:

  1. Parentheses ()
  2. Multiplication/Division * /
  3. Addition/Subtraction + -
  4. NOT
  5. AND
  6. OR

Rule of Thumb: Always use Parentheses () when mixing AND/OR to ensure clarity!


📈 Learning Path

📍 Visit Us

🏫 VD Computer Tuition Surat

VD Computer Tuition
📍 Address
2/66 Faram Street, Rustompura
Surat395002, Gujarat, India
📞 Phone / WhatsApp
+91 84604 41384
🌐 Website

Computer Classes & Tuition — Areas We Serve in Surat

AdajanAlthanAmroliAthwaAthwalinesBhagalBhatarBhestanCanal RoadChowkCitylightDumasGaurav PathGhod Dod RoadHaziraJahangirpuraKamrejKapodraKatargamLimbayatMagdallaMajura GateMota VarachhaNanpuraNew CitylightOlpadPalPandesaraParle PointPiplodPunaRanderRing RoadRustampuraSachinSalabatpuraSarthanaSosyo CircleUdhnaVarachhaVed RoadVesuVIP Road
📞 Call Sir💬 WhatsApp Sir