Curriculum
Filtering Data is one of the most powerful and frequently used SQL skills in Data Analytics. After retrieving information using the SELECT Statement, Data Analysts often need only specific records rather than entire datasets. Filtering Data allows users to narrow down results based on conditions, making reports more meaningful and efficient.
Organizations store millions of records in databases. A sales database may contain years of transaction history, a customer database may contain millions of users, and an HR system may contain thousands of employee records. Without Filtering Data, analysts would struggle to find relevant information quickly.
Businesses use Filtering Data to:
Mastering Filtering Data is essential for Data Analysts, Business Analysts, Database Administrators, and Business Intelligence professionals.
Filtering Data is the process of retrieving only those records that meet specific conditions.
Instead of displaying all records, SQL returns only the rows that satisfy the specified criteria.
Example:
A customer table contains 10,000 records.
Management wants customers from Jaipur only.
Filtering Data allows SQL to retrieve only those relevant records.
Benefits:
The WHERE clause is the primary tool used for Filtering Data.
SELECT column_name
FROM table_name
WHERE condition;
The WHERE clause tells SQL which records should be included in the result.
Table:
| CustomerID | CustomerName | City |
|---|---|---|
| 101 | Rahul Sharma | Jaipur |
| 102 | Priya Verma | Delhi |
| 103 | Amit Kumar | Jaipur |
Query:
SELECT *
FROM Customers
WHERE City = 'Jaipur';
Result:
| CustomerID | CustomerName | City |
|---|---|---|
| 101 | Rahul Sharma | Jaipur |
| 103 | Amit Kumar | Jaipur |
Only customers from Jaipur are returned.
SQL uses comparison operators for filtering.
Example:
SELECT *
FROM Employees
WHERE Department = 'HR';
Returns only HR employees.
Example:
SELECT *
FROM Employees
WHERE Department != 'HR';
Returns all employees except HR employees.
Example:
SELECT *
FROM Sales
WHERE Revenue > 50000;
Returns sales records above ₹50,000.
Example:
SELECT *
FROM Sales
WHERE Revenue < 50000;
Returns sales records below ₹50,000.
Example:
SELECT *
FROM Sales
WHERE Revenue >= 50000;
Returns records equal to or greater than ₹50,000.
Example:
SELECT *
FROM Sales
WHERE Revenue <= 50000;
Returns records equal to or below ₹50,000.
Numeric filtering is common in business reporting.
Example:
SELECT ProductName,
Revenue
FROM Sales
WHERE Revenue > 100000;
Applications:
Example:
SELECT CustomerName
FROM Customers
WHERE City = 'Delhi';
Applications:
Example:
SELECT *
FROM Orders
WHERE OrderDate = '2026-06-01';
Applications:
AND combines multiple conditions.
SELECT *
FROM table_name
WHERE condition1
AND condition2;
Example:
SELECT *
FROM Employees
WHERE Department = 'IT'
AND Salary > 50000;
Result:
Only IT employees earning more than ₹50,000 are displayed.
Benefits:
More precise filtering.
OR returns records that satisfy at least one condition.
Example:
SELECT *
FROM Customers
WHERE City = 'Jaipur'
OR City = 'Delhi';
Result:
Customers from Jaipur or Delhi.
Benefits:
Broader filtering.
NOT excludes matching records.
Example:
SELECT *
FROM Employees
WHERE NOT Department = 'HR';
Result:
All employees except HR employees.
Applications:
Exclusion reporting.
BETWEEN filters values within a range.
SELECT *
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
Example:
SELECT *
FROM Sales
WHERE Revenue BETWEEN 50000 AND 100000;
Result:
Sales between ₹50,000 and ₹100,000.
Applications:
Revenue analysis.
IN simplifies multiple-value filtering.
Example:
SELECT *
FROM Customers
WHERE City IN ('Jaipur', 'Delhi', 'Mumbai');
Result:
Customers from selected cities.
Benefits:
Cleaner queries.
LIKE searches for patterns.
Example:
SELECT *
FROM Customers
WHERE CustomerName LIKE 'R%';
Result:
Names starting with R.
Examples:
Example:
SELECT *
FROM Customers
WHERE CustomerName LIKE '%a';
Result:
Names ending with “a”.
Example:
SELECT *
FROM Customers
WHERE CustomerName LIKE '%sh%';
Result:
Names containing “sh”.
Applications:
Search functionality.
Find missing values.
Example:
SELECT *
FROM Employees
WHERE Email IS NULL;
Result:
Employees without email addresses.
Applications:
Data quality checks.
Find available values.
Example:
SELECT *
FROM Employees
WHERE Email IS NOT NULL;
Result:
Employees with email addresses.
Applications:
Data completeness validation.
Example:
SELECT *
FROM Sales
WHERE Revenue > 100000;
Benefits:
Identify top-performing transactions.
Applications:
Revenue reporting.
Example:
SELECT *
FROM Customers
WHERE City = 'Jaipur';
Benefits:
Regional customer analysis.
Applications:
Marketing campaigns.
Example:
SELECT *
FROM Employees
WHERE Department = 'Finance';
Benefits:
Department-specific reporting.
Applications:
Workforce analysis.
Example:
SELECT *
FROM Transactions
WHERE Amount > 50000;
Benefits:
Monitor high-value transactions.
Applications:
Financial audits.
Example:
SELECT *
FROM Sales
WHERE Region = 'North'
AND Revenue > 100000
AND OrderDate >= '2026-01-01';
Benefits:
Highly targeted reporting.
Applications:
Executive dashboards.
Example:
WHERE Revenue = '50000'
Use appropriate numeric formats.
Incorrect:
WHERE City = Jaipur
Correct:
WHERE City = 'Jaipur'
May produce unexpected results.
Can lead to incomplete analysis.
Avoid these mistakes to improve query accuracy.
Improve relevance.
Ensure logical accuracy.
Confirm expected outputs.
Simplify queries.
Improve data quality analysis.
Retrieve only necessary records.
These practices improve SQL performance and reporting quality.
Data Analysts use Filtering Data for:
Filtering Data is one of the most frequently used SQL skills in analytics.
Organizations benefit through:
Filtering Data helps transform large datasets into meaningful business information.
After completing this lesson, you will be able to:
Filtering Data is the process of retrieving only records that meet specific conditions.
The WHERE clause is used for Filtering Data.
BETWEEN retrieves records within a specified range.
LIKE searches for text patterns.
IN allows filtering using multiple values.
IS NULL identifies missing values.
AND requires all conditions to be true, while OR requires at least one condition to be true.
It allows analysts to focus on relevant information and generate meaningful insights.
Want to master SQL, reporting, and Data Analytics?
WhatsApp us