Advanced Filtering

Advanced filtering combines multiple conditions in a single query using logical operators, giving you precise control over exactly which rows are returned.

AND, OR, NOT

-- Both conditions must be true
SELECT * FROM customers
WHERE city = 'Noida' AND signup_date > '2025-01-01';

-- Either condition can be true
SELECT * FROM customers
WHERE city = 'Noida' OR city = 'Delhi';

-- Exclude matching rows
SELECT * FROM customers
WHERE NOT city = 'Noida';

IN - Matching Multiple Values

SELECT * FROM customers
WHERE city IN ('Noida', 'Delhi', 'Gurugram');

BETWEEN - Matching a Range

SELECT * FROM orders
WHERE amount BETWEEN 1000 AND 5000;

Combining Conditions with Parentheses

When mixing AND and OR, parentheses control the order of evaluation, just like in mathematical expressions:

SELECT * FROM customers
WHERE (city = 'Noida' OR city = 'Delhi') AND signup_date > '2025-01-01';
Without parentheses, SQL evaluates AND before OR - so mixing them without grouping can silently produce a different result than intended.

Ready to Master Data Science?

Join Uncodemy's Data Science Course and build real, job-ready skills with expert mentors.

Explore Course