Coding Now – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 9667708830
Back to SQL Notes
Topic #203

SQL WHERE Clause

WHERE filters rows before they're returned — only rows matching the condition make it into the result.

Syntax

SELECT columns
FROM table_name
WHERE condition;

Sample Table: employees

idnamedepartmentsalary
1AmanEngineering65000
2RiyaMarketing52000
3KaranEngineering71000

Example

SELECT name, salary
FROM employees
WHERE salary > 60000;

Output:

namesalary
Aman65000
Karan71000

Comparison Operators

OperatorMeaning
=equal to
<> or !=not equal to
>, <greater than, less than
>=, <=greater than or equal, less than or equal

Combining Conditions

SELECT name FROM employees
WHERE department = 'Engineering' AND salary > 60000;

See AND / OR for combining multiple conditions in detail.

Practical Use Case

Almost every real query has a WHERE clause — active users only, orders from this month, products in stock. It's the difference between "all the data" and "the data that actually answers the question."

Common Mistakes

  • Confusing WHERE (filters individual rows, runs before grouping) with HAVING (filters grouped results, runs after grouping) — see WHERE vs HAVING
  • Using = to compare against NULL — this never matches; use IS NULL instead
  • Forgetting quotes around string/date literals: WHERE department = Engineering is invalid — it must be 'Engineering'

Interview Relevance

Filtering logic shows up in nearly every SQL interview question. Interviewers are often less interested in the syntax and more in whether you correctly translate a business requirement ("active customers who spent over ₹10,000 last quarter") into the right conditions.

Practice Question

Write a query to find all employees in the "Marketing" department earning less than 55,000.

Related SQL Notes

Want to go beyond the notes?

Join CodingNow's SQL course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →