What is the SQL WHERE clause?

Overview

The SQL WHERE clause is used to filter records to only obtain those that satisfy the given condition.

Syntax

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

Students

StudentID

StudentName

City

Country

1

Saad Qureshi

Michigan

U.S.A.

2

John Snow

Berlin

Germany

3

Erin White

New York

U.S.A.

4

Ethan Goldberg

Paris

France

The WHERE clause can be applied to the following table.

Example 1

SELECT * FROM Students
WHERE Country='U.S.A.';

The statement above filters out the Students on the basis of the Country, where the Country is U.S.A..

Note: SQL requires single quotes around text values. However, this is not the case for numerical fields, which do not require any quotes.

Example 2

SELECT * FROM Students
WHERE StudentID=3;

The statement above filters out the Students on the basis of the StudentID, where the StudentID is 3.

New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources