100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
SQL

Filtering with WHERE

Use the WHERE clause to filter rows returned by a query based on specified conditions.

SQL BasicsBeginner9 min readJul 8, 2026
Analogies

Introduction

The WHERE clause lets you filter the rows returned by a SELECT statement so that only rows meeting a specific condition are included. Without WHERE, a query returns every row in the table; with WHERE, you can narrow results to exactly what you need.

🏏

Cricket analogy: A scout reviewing every player in the IPL auction list without filters sees thousands of names, but adding a condition like 'only fast bowlers under 25' narrows it to exactly the shortlist a franchise needs.

Syntax

sql
SELECT column1, column2, ...
FROM table_name
WHERE condition;

-- Combining conditions
SELECT column1
FROM table_name
WHERE condition1 AND condition2
   OR condition3;

Explanation

The WHERE clause evaluates a boolean condition for each row; only rows for which the condition is true are included in the result. Conditions can use comparison operators (=, <>, <, >, <=, >=), logical operators (AND, OR, NOT), and special operators such as BETWEEN, IN, LIKE, and IS NULL. WHERE is applied before any grouping or aggregation happens.

🏏

Cricket analogy: A selector's condition might be 'strike rate > 140 AND average > 35' evaluated per batter; only those satisfying both comparisons make the T20 squad, while BETWEEN could check 'age between 19 and 23' for youth picks.

Example

sql
-- employees table: id, first_name, last_name, department, salary, hire_date

SELECT first_name, last_name, salary
FROM employees
WHERE department = 'Engineering'
  AND salary > 80000;

Output

Only rows where the department is exactly 'Engineering' and salary exceeds 80000 are returned, for example: 'Alice | Nguyen | 95000'. Employees in other departments or with lower salaries are excluded entirely from the result set.

🏏

Cricket analogy: A query for 'team = Mumbai Indians AND runs > 400' would return only 'Rohit | Sharma | 2023-final' style rows, silently dropping every other franchise's matches and lower-scoring games.

Key Takeaways

  • WHERE filters individual rows before any aggregation occurs.
  • Use AND/OR/NOT to combine multiple conditions; parentheses control precedence.
  • Use IS NULL / IS NOT NULL to test for missing values, not = NULL.
  • BETWEEN, IN, and LIKE provide concise ways to express common filter patterns.

Practice what you learned

Was this page helpful?

Topics covered

#SQL#DatabaseSQLStudyNotes#Database#FilteringWithWHERE#Filtering#WHERE#Syntax#Explanation#StudyNotes#SkillVeris