Loading
The WHERE clause in SQL is used to filter records from a table based on specific conditions. It helps retrieve only the data you need, making your queries more efficient and relevant.



What is the WHERE Clause?

  • It filters records that meet the given condition(s).
  • It can be used with any SELECT, UPDATE, DELETE, or INSERT query.
  • It simplifies data aggregation by narrowing down the results.
  • Conditions are specified using comparison operators (like =, >, <, etc.).


Syntax:

SELECT column_name FROM table_name WHERE condition;

  • column_name: Name of the column(s) to retrieve.
  • table_name: Name of the table to query from.
  • condition: Logic used to filter data (e.g., AGE > 25).



Common Operators Used with WHERE

OperatorDescription
=Equal to 
<> or !=Not equal to
>Greater than
<Less than
>=Greater than or equal to
<=Less than or equal to
AND, ORCombine multiple conditions
LIKEPattern matching
INMatches any in a list



EMPLOYEES Table

IDNAMEAGEADDRESSSALARY
1Shweta25MumbaiRs 12000
2Raj26GoaRs 25000
3Abhi30KarnatakaRs 18000
4Roshani32KeralaRs 15000



Example: Using = (Equal To)

SELECT ID, NAME FROM EMPLOYEES WHERE AGE = 32;

Output:

IDNAME
4Roshani

Explanation: Fetches employees where the AGE is exactly 32.



Example: Using < (Less Than)

SELECT ID, NAME FROM EMPLOYEES WHERE SALARY < 20000;

Output:

IDNAME
1Shweta
3Abhi
4Roshani

Explanation: Returns employees with a salary less than Rs 20,000.



Key Point

  • The WHERE clause is essential for filtering specific rows.
  • Combine multiple conditions with AND or OR for advanced filtering.
  • Use it to improve query performance and extract only what is needed.