Professional Documents
Culture Documents
The SQL AND, OR and NOT Operators
The SQL AND, OR and NOT Operators
AND, OR and
NOT Operators
❮ PreviousNext ❯
AND Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition1 AND condition2 AND condition3 ...;
OR Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition1 OR condition2 OR condition3 ...;
NOT Syntax
SELECT column1, column2, ...
FROM table_name
WHERE NOT condition;
Demo Database
The table below shows the complete "Customers" table from the Northwind
sample database:
4 Around the Horn Thomas Hardy 120 Hanover Sq. London WA1
12 Cactus Comidas para Patricio Simpson Cerrito 333 Buenos Aires 1010
llevar
13 Centro comercial Francisco Chang Sierras de Granada 9993 México D.F. 0502
Moctezuma
15 Comércio Mineiro Pedro Afonso Av. dos Lusíadas, 23 São Paulo 0543
18 Du monde entier Janine Labrune 67, rue des Cinquante Nantes 4400
Otages
32 Great Lakes Food Howard Snyder 2732 Baker Blvd. Eugene 9740
Market
43 Lazy K Kountry Store John Steel 12 Orchestra Terrace Walla Walla 9936
45 Let's Stop N Shop Jaime Yorres 87 Polk St. Suite 5 San 9411
Francisco
46 LILA-Supermercado Carlos González Carrera 52 con Ave. Barquisimeto 3508
Bolívar #65-98 Llano
Largo
54 Océano Atlántico Yvonne Moncada Ing. Gustavo Moncada Buenos Aires 1010
Ltda. 8585 Piso 20-A
55 Old World Rene Phillips 2743 Bering St. Anchorage 9950
Delicatessen
58 Pericles Comidas Guillermo Calle Dr. Jorge Cash 321 México D.F. 0503
clásicas Fernández
62 Queen Cozinha Lúcia Carvalho Alameda dos Canàrios, São Paulo 0548
891
64 Rancho grande Sergio Gutiérrez Av. del Libertador 900 Buenos Aires 1010
65 Rattlesnake Canyon Paula Wilson 2817 Milton Dr. Albuquerque 8711
Grocery
75 Split Rail Beer & Ale Art P.O. Box 555 Lander 8252
Braunschweiger
77 The Big Cheese Liz Nixon 89 Jefferson Way Suite 2 Portland 9720
78 The Cracker Box Liu Wong 55 Grizzly Peak Rd. Butte 5980
80 Tortuga Restaurante Miguel Angel Avda. Azteca 123 México D.F. 0503
Paolino
82 Trail's Head Gourmet Helvetius Nagy 722 DaVinci Blvd. Kirkland 9803
Provisioners
89 White Clover Markets Karl Jablonski 305 - 14th Ave. S. Suite Seattle 9812
3B
AND Example
The following SQL statement selects all fields from "Customers" where country
is "Germany" AND city is "Berlin":
Example
SELECT * FROM Customers
WHERE Country='Germany' AND City='Berlin';
Try it Yourself »
OR Example
The following SQL statement selects all fields from "Customers" where city is
"Berlin" OR "München":
Example
SELECT * FROM Customers
WHERE City='Berlin' OR City='München';
Try it Yourself »
The following SQL statement selects all fields from "Customers" where country
is "Germany" OR "Spain":
Example
SELECT * FROM Customers
WHERE Country='Germany' OR Country='Spain';
Try it Yourself »
NOT Example
The following SQL statement selects all fields from "Customers" where country
is NOT "Germany":
Example
SELECT * FROM Customers
WHERE NOT Country='Germany';
Try it Yourself »
Combining AND, OR and NOT
You can also combine the AND, OR and NOT operators.
The following SQL statement selects all fields from "Customers" where country
is "Germany" AND city must be "Berlin" OR "München" (use parenthesis to form
complex expressions):
Example
SELECT * FROM Customers
WHERE Country='Germany' AND (City='Berlin' OR City='München');
Try it Yourself »
The following SQL statement selects all fields from "Customers" where country
is NOT "Germany" and NOT "USA":
Example
SELECT * FROM Customers
WHERE NOT Country='Germany' AND NOT Country='USA';
Try it Yourself »
* FROM Customers
City = 'Berlin'
= 12209;
Submit Answer »
COLOR PICKER
LIKE US
Get certified
by completing
a course today!
w3schoolsCERTIFIED.2021
Get started
CODE GAME
Play Game
REPORT ERROR
FORUM
ABOUT
SHOP
Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
W3.CSS Tutorial
Bootstrap Tutorial
PHP Tutorial
Java Tutorial
C++ Tutorial
jQuery Tutorial
Top References
HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
Python Reference
W3.CSS Reference
Bootstrap Reference
PHP Reference
HTML Colors
Java Reference
Angular Reference
jQuery Reference
Top Examples
HTML Examples
CSS Examples
JavaScript Examples
How To Examples
SQL Examples
Python Examples
W3.CSS Examples