TGViewer
SQL Programming Resources SQL Programming Resources @sqlanalyst · 76.7K subscribers
Post #2221 4.13K
✅ SQL Basics: Part-3: Filtering with SQL Operators

Filtering helps you narrow down results based on specific conditions.

Let’s explore some powerful SQL operators:

1️⃣ IN – Match multiple values
Syntax:
SELECT columns FROM table_name WHERE column IN (value1, value2,...);

Example:
Get customers from specific cities:
SELECT name, city FROM customers
WHERE city IN ('Delhi', 'Mumbai', 'Chennai');


2️⃣ OR – Match any of multiple conditions
Syntax:
SELECT columns FROM table_name WHERE condition1 OR condition2;

Example:
Get employees from HR or Finance:
SELECT name FROM employees
WHERE department = 'HR' OR department = 'Finance';


3️⃣ AND – Match all conditions
Syntax:
SELECT columns FROM table_name WHERE condition1 AND condition2;

Example:
Get Sales employees earning more than 60,000:
SELECT name FROM employees
WHERE department = 'Sales' AND salary > 60000;


4️⃣ NOT – Exclude specific values or conditions
Syntax:
SELECT columns FROM table_name WHERE NOT condition;

Example:
Get all products except Electronics:
SELECT * FROM products
WHERE NOT category = 'Electronics';


5️⃣ BETWEEN – Match a range of values (inclusive)
Syntax:
SELECT columns FROM table_name WHERE column BETWEEN value1 AND value2;

Example:
Get employees with salary between 50,000 and 100,000:
SELECT name, salary FROM employees
WHERE salary BETWEEN 50000 AND 100000;


🔥 Quick Practice Task:
Write a query to:
• Get all employees in 'IT' or 'HR'
• Who earn more than 50,000
• Show name, department, and salary:
SELECT name, department, salary
FROM employees
WHERE department IN ('IT', 'HR')
AND salary > 50000;


✅ SQL Filtering Interview QA 💼🧠

Q1. What’s the difference between AND and OR?
A:
• AND requires all conditions to be true
• OR requires at least one condition to be true

Q2. Can you combine AND and OR in one query?
A: Yes, but use parentheses to control logic:
SELECT * FROM employees
WHERE (department = 'Sales' OR department = 'Marketing')
AND salary > 60000;


Q3. What does NOT IN do?
A: Excludes rows with values in the list:
SELECT * FROM customers
WHERE city NOT IN ('Delhi', 'Mumbai');


Q4. Can BETWEEN be used with dates?
A: Absolutely!
SELECT * FROM orders
WHERE order_date BETWEEN '2025-01-01' AND '2025-01-31';


Q5. What’s the difference between IN and multiple ORs?
A: IN is cleaner and more concise:
-- Instead of:
WHERE city = 'A' OR city = 'B' OR city = 'C';

-- Use:
WHERE city IN ('A', 'B', 'C');


💡 Pro Tip:
When combining multiple filters, always use parentheses to avoid unexpected results due to operator precedence.

SQL Roadmap

DOUBLE TAP ❤️ FOR MORE
  • ❤ 12
More from @sqlanalyst
  1. Oct 13, 2026SQL Interview Series — Part 8 📌 Question 8: Find Customers Who Have Never Placed an Order…
  2. Oct 13, 2026𝗧𝗢𝗣 𝗙𝗥𝗘𝗘 𝗖𝗢𝗨𝗥𝗦𝗘𝗦 𝗧𝗢 𝗕𝗢𝗢𝗦𝗧 𝗬𝗢𝗨𝗥 𝗦𝗞𝗜𝗟𝗟𝗦 𝗜𝗡 𝟮𝟬𝟮𝟲! Explor…
  3. Oct 12, 2026SQL Interview Series — Part 6 📌 Question 6: Find the Top 2 Highest-Paid Employees in Each…
  4. Oct 12, 2026🚀 𝗪𝗵𝗶𝗰𝗵 𝗧𝗲𝗰𝗵 𝗦𝗸𝗶𝗹𝗹 𝗪𝗶𝗹𝗹 𝗬𝗼𝘂 𝗠𝗮𝘀𝘁𝗲𝗿 𝗶𝗻 𝟮𝟬𝟮𝟲? Want to buil…
  5. Oct 9, 2026SQL Interview Series — Part 5 📌 Question 5: Find Employees Who Earn More Than Their Manag…
  6. Oct 9, 2026🇮🇳 𝗚𝗢𝗩𝗘𝗥𝗡𝗠𝗘𝗡𝗧 𝗢𝗙 𝗜𝗡𝗗𝗜𝗔 — 𝗔𝗜𝗖𝗧𝗘 𝗜𝗡𝗧𝗘𝗥𝗡𝗦𝗛𝗜𝗣𝗦 𝟮𝟬𝟮𝟲 🚀…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →