Tutorials Exercises Services Sign Up Log in
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
MySQL WHERE Clause
❮ Previous Next ❯
The MySQL WHERE Clause
The WHERE clause is used to filter records.
It is used to extract only those records that fulfill a specified condition.
WHERE Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition;
Note: The WHERE clause is not only used in SELECT statements, it is also used in
UPDATE , DELETE , etc.!
Demo Database
Below is a selection from the "Customers" table in the Northwind sample database:
CustomerID
Tutorials Exercises Services
CustomerName ContactName
Address
Sign Up
City
Log in
PostalCod
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
1 Alfreds Maria Anders Obere Str. 57 Berlin 12209
Futterkiste
2 Ana Trujillo Ana Trujillo Avda. de la México 05021
Emparedados y Constitución D.F.
helados 2222
3 Antonio Moreno Antonio Mataderos México 05023
Taquería Moreno 2312 D.F.
4 Around the Horn Thomas Hardy 120 Hanover London WA1 1DP
Sq.
5 Berglunds Christina Berguvsvägen Luleå S-958 22
snabbköp Berglund 8
WHERE Clause Example
The following SQL statement selects all the customers from "Mexico":
Example Get your own SQL Server
SELECT * FROM Customers
WHERE Country = 'Mexico';
Try it Yourself »
Text Fields vs. Numeric Fields
SQL requires single quotes around text values (most database systems will also allow
Tutorials
double quotes). Exercises Services Sign Up Log in
HTML CSSnumeric
However, JAVASCRIPT
fields shouldSQL
not bePYTHON
enclosed inJAVA
quotes: PHP HOW TO W3.CSS C
Example
SELECT * FROM Customers
WHERE CustomerID = 1;
Try it Yourself »
Operators in The WHERE Clause
The following operators can be used in the WHERE clause:
Operator Description Example
= Equal Try it
> Greater than Try it
< Less than Try it
>= Greater than or equal Try it
<= Less than or equal Try it
<> Not equal. Note: In some versions of SQL this operator Try it
may be written as !=
BETWEEN Between a certain range Try it
LIKE Search for a pattern Try it
IN To specify multiple possible values for a column Try it
Tutorials Exercises Services Sign Up Log in
TestCSS
HTML
Yourself With
JAVASCRIPT SQL
Exercises
PYTHON JAVA PHP HOW TO W3.CSS C
Exercise:
Select all records where the City column has the value "Berlin".
SELECT * FROM Customers
= ;
Submit Answer »
Start the Exercise
❮ Previous Log in to track progress Next ❯
Tutorials Exercises Services Sign Up Log in
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
COLOR PICKER
Tutorials Exercises Services Sign Up Log in
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
SPACES UPGRADE NEWSLETTER
GET CERTIFIED REPORT ERROR
Top Tutorials Top References
Tutorials Exercises Services Sign Up Log in
HTML Tutorial HTML Reference
HTML
CSS CSS Tutorial
JAVASCRIPT SQL PYTHON CSS Reference PHP
JAVA HOW TO W3.CSS C
JavaScript Tutorial JavaScript Reference
How To Tutorial SQL Reference
SQL Tutorial Python Reference
Python Tutorial W3.CSS Reference
W3.CSS Tutorial Bootstrap Reference
Bootstrap Tutorial PHP Reference
PHP Tutorial HTML Colors
Java Tutorial Java Reference
C++ Tutorial Angular Reference
jQuery Tutorial jQuery Reference
Top Examples Get Certified
HTML Examples HTML Certificate
CSS Examples CSS Certificate
JavaScript Examples JavaScript Certificate
How To Examples Front End Certificate
SQL Examples SQL Certificate
Python Examples Python Certificate
W3.CSS Examples PHP Certificate
Bootstrap Examples jQuery Certificate
PHP Examples Java Certificate
Java Examples C++ Certificate
XML Examples C# Certificate
jQuery Examples XML Certificate
FORUM ABOUT
W3Schools is optimized for learning and training. Examples might be simplified to
improve reading and learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we
cannot warrant full correctness
of all content. While using W3Schools, you agree to have read and accepted our terms of
use, cookie and privacy policy.
Copyright 1999-2023 by Refsnes Data. All Rights Reserved. W3Schools is Powered by
W3.CSS.
Tutorials Exercises Services Sign Up Log in
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C