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_nameWHERE 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 StudentsWHERE 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 StudentsWHERE StudentID=3;
The statement above filters out the Students on the basis of the StudentID, where the StudentID is 3.