TGViewer
SQL Programming Resources SQL Programming Resources @sqlanalyst ยท 76.7K subscribers
Post #2345 5.18K
๐Ÿ” SQL Fundamentals Part-2: Filtering

After learning SELECT basics, the next step is learning how to filter data.

๐Ÿ‘‰ In real-world data analysis, you rarely need full data โ€” you filter specific rows.

Filtering = extracting only relevant data from a table.

โœ… What is Filtering in SQL?
Filtering is done using the WHERE clause.

It allows you to:
โœ” Get specific records
โœ” Apply conditions
โœ” Clean data
โœ” Extract business insights

๐Ÿ”น 1. Comparison Operators
Used to compare values.
Operator Meaning
โ€ข = Equal
โ€ข > Greater than
โ€ข < Less than
โ€ข >= Greater than or equal
โ€ข <= Less than or equal
โ€ข != or <> Not equal

โœ… Examples

โ€ข Equal to
SELECT * FROM employees WHERE city = 'Pune';

โ€ข Greater than
SELECT * FROM employees WHERE salary > 50000;

โ€ข Not equal
SELECT * FROM employees WHERE department != 'HR';

๐Ÿ’ก Most commonly used in dashboards reporting.

๐Ÿ”น 2. Logical Operators (AND, OR, NOT)

Used to combine multiple conditions.

โœ… AND โ€” Both conditions must be true

SELECT * FROM employees WHERE salary > 50000 AND city = 'Mumbai';

๐Ÿ‘‰ Returns employees with: salary > 50000 AND located in Mumbai

โœ… OR โ€” Any condition can be true

SELECT * FROM employees WHERE city = 'Delhi' OR city = 'Pune';

๐Ÿ‘‰ Returns employees from either city.

โœ… NOT โ€” Reverse condition

SELECT * FROM employees WHERE NOT department = 'Sales';

๐Ÿ‘‰ Excludes Sales department.

๐Ÿ”น 3. BETWEEN (Range Filtering)

Used to filter values within a range.

Syntax
SELECT * FROM table WHERE column BETWEEN value1 AND value2;

โœ… Example
SELECT * FROM employees WHERE salary BETWEEN 30000 AND 70000;

๐Ÿ‘‰ Includes boundary values.

๐Ÿ”น 4. IN Operator (Multiple Values Shortcut)

Better alternative to multiple OR conditions.

โŒ Without IN
WHERE city = 'Pune' OR city = 'Delhi' OR city = 'Mumbai'

โœ… With IN
SELECT * FROM employees WHERE city IN ('Pune','Delhi','Mumbai');

๐Ÿ‘‰ Cleaner and faster.

๐Ÿ”น 5. LIKE โ€” Pattern Matching
Used for searching text patterns.

โญ Wildcards
Symbol Meaning
โ€ข % Any number of characters
โ€ข _ Single character

โœ… Starts with "A"
SELECT * FROM customers WHERE name LIKE 'A%';

โœ… Ends with "n"
WHERE name LIKE '%n';

โœ… Contains "an"
WHERE name LIKE '%an%';

Used heavily in search features.

๐Ÿ”น 6. NULL Handling (Very Important โญ)

NULL means:
๐Ÿ‘‰ Missing / unknown value
๐Ÿ‘‰ Not zero
๐Ÿ‘‰ Not empty

โŒ Wrong
WHERE salary = NULL

โœ… Correct
SELECT * FROM employees WHERE salary IS NULL;

Check non-null values
WHERE salary IS NOT NULL;

๐Ÿ’ก Very common interview question.

โญ Order of Filtering Execution
SQL processes filtering after reading table:

FROM โ†’ WHERE โ†’ SELECT โ†’ ORDER BY โ†’ LIMIT

๐Ÿง  Real-World Data Analyst Examples

Q. Find customers from Pune
SELECT * FROM customers WHERE city = 'Pune';

Q. Find high-paying jobs in IT department
SELECT * FROM employees WHERE salary > 80000 AND department = 'IT';

Q. Find names starting with "R"
SELECT * FROM employees WHERE name LIKE 'R%';

Used daily in business analytics.

๐Ÿš€ Mini Practice Tasks
โœ… Q1
Find employees whose salary is greater than 60000.
โœ… Q2
Find customers from Pune or Mumbai.
โœ… Q3
Find products priced between 100 and 500.
โœ… Q4
Find employees whose name starts with "S".
โœ… Q5
Find records where email is missing (NULL).

โœ… Double Tap โ™ฅ๏ธ For More
  • โค 8
More from @sqlanalyst
  1. Oct 12, 2026๐Ÿš€ ๐—ช๐—ต๐—ถ๐—ฐ๐—ต ๐—ง๐—ฒ๐—ฐ๐—ต ๐—ฆ๐—ธ๐—ถ๐—น๐—น ๐—ช๐—ถ๐—น๐—น ๐—ฌ๐—ผ๐˜‚ ๐— ๐—ฎ๐˜€๐˜๐—ฒ๐—ฟ ๐—ถ๐—ป ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ? Want to builโ€ฆ
  2. Oct 9, 2026SQL Interview Series โ€” Part 5 ๐Ÿ“Œ Question 5: Find Employees Who Earn More Than Their Managโ€ฆ
  3. Oct 9, 2026๐Ÿ‡ฎ๐Ÿ‡ณ ๐—š๐—ข๐—ฉ๐—˜๐—ฅ๐—ก๐— ๐—˜๐—ก๐—ง ๐—ข๐—™ ๐—œ๐—ก๐——๐—œ๐—” โ€” ๐—”๐—œ๐—–๐—ง๐—˜ ๐—œ๐—ก๐—ง๐—˜๐—ฅ๐—ก๐—ฆ๐—›๐—œ๐—ฃ๐—ฆ ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ ๐Ÿš€โ€ฆ
  4. Oct 8, 2026๐ŸŽ“ ๐— ๐—ถ๐—ฐ๐—ฟ๐—ผ๐˜€๐—ผ๐—ณ๐˜ ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ๐˜€ ๐˜„๐—ถ๐˜๐—ต ๐—–๐—ฒ๐—ฟ๐˜๐—ถ๐—ณ๐—ถ๐—ฐ๐—ฎ๐˜๐—ฒ๐˜€! ๐Ÿš€๐Ÿ”ฅ Upgrโ€ฆ
  5. Oct 7, 2026๐Ÿš€๐—ฃ๐—ฎ๐˜† ๐—”๐—ณ๐˜๐—ฒ๐—ฟ ๐—ฃ๐—น๐—ฎ๐—ฐ๐—ฒ๐—บ๐—ฒ๐—ป๐˜ ๐—ง๐—ฟ๐—ฎ๐—ถ๐—ป๐—ถ๐—ป๐—ด | ๐—•๐—ฒ๐—ฐ๐—ผ๐—บ๐—ฒ ๐—ฎ ๐—™๐˜‚๐—น๐—น๐˜€๐˜๐—ฎ๐—ฐโ€ฆ
  6. Oct 7, 2026SQL Interview Series โ€” Part 4 ๐Ÿ“Œ Question 4: Find the Highest Salary in Each Department Suโ€ฆ
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 โ†’