⚡ 180+ new openings posted today

SQL WHERE Clause

What is the WHERE Clause ?

Answer : The WHERE Clause is used to filter records. It is used to extract only those records that fulfill a specified conditions.

Syntax

SELECT column_name FROM table_name WHERE conditions;

Example

Suppose we have an Employees table:

Employee_IDEmployee_NameSalary
101Anjali50000
102Priya45000
103Amit55000

If we want to find employees whose salary is greater than 50000:

SELECT *
FROM Employees
WHERE Salary > 50000;

Operators Used with the WHERE Clause

1. Comparison Operators

OperatorMeaningExample
=Equal toSalary = 50000
<> or !=Not equal toSalary <> 50000
>Greater thanSalary > 50000
<Less thanSalary < 50000
>=Greater than or equal toSalary >= 50000
<=Less than or equal toSalary <= 50000

2. Logical Operators

OperatorMeaningExample
ANDBoth conditions must be trueSalary > 40000 AND Salary < 60000
ORAt least one condition must be trueSalary > 50000 OR Employee_ID = 101
NOTReverses a conditionNOT Salary > 50000

3. Other Common Operators

OperatorPurposeExample
BETWEENChecks a rangeSalary BETWEEN 40000 AND 60000
INMatches multiple valuesEmployee_ID IN (101, 102)
LIKESearches for a patternEmployee_Name LIKE 'R%'
IS NULLChecks for NULL valuesSalary IS NULL
IS NOT NULLChecks for non-NULL valuesSalary IS NOT NULL

To fetch the record of the employee whose name is “Priya”:

SELECT *
FROM Employees
WHERE Employee_Name = ‘Priya’;

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top