SQL and or Not
SQL and or Not
com
The AND and OR operators are used to filter records based on more than one condition:
The AND operator displays a record if all the conditions separated by AND are TRUE.
The OR operator displays a record if any of the conditions separated by OR is TRUE.
AND Syntax
OR Syntax
NOT Syntax
Demo Database
Below is a selection from the "Customers" table in the Northwind sample database:
AND Example
The following SQL statement selects all fields from "Customers" where country is "Germany" AND city is
"Berlin":
Example
Try it Yourself »
OR Example
The following SQL statement selects all fields from "Customers" where city is "Berlin" OR "München":
Example
Try it Yourself »
NOT Example
The following SQL statement selects all fields from "Customers" where country is NOT "Germany":
Example
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
Try it Yourself »
The following SQL statement selects all fields from "Customers" where country is NOT "Germany" and NOT
"USA":
Example
Try it Yourself »
Exercise:
Select all records where the City column has the value 'Berlin' and the PostalCode
column has the value 12209.
* FROM Customers
City = 'Berlin'
= 12209;
Submit Answer »
❮ Previous Next ❯
COLOR PICKER
Exercises
HTML
CSS
JavaScript
SQL
PHP
Python
Bootstrap
jQuery
SHARE
CERTIFICATES
HTML
CSS
JavaScript
PHP
jQuery
Bootstrap
XML
Read More »
REPORT ERROR
PRINT PAGE
FORUM
ABOUT
Top 10 Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
W3.CSS Tutorial
Bootstrap Tutorial
SQL Tutorial
PHP Tutorial
jQuery Tutorial
Python Tutorial
Top 10 References
HTML Reference
CSS Reference
JavaScript Reference
W3.CSS Reference
Bootstrap Reference
SQL Reference
PHP Reference
HTML Colors
jQuery Reference
Python Reference
Top 10 Examples
HTML Examples
CSS Examples
JavaScript Examples
How To Examples
W3.CSS Examples
Bootstrap Examples
PHP Examples
jQuery Examples
Angular Examples
XML Examples
Web Certificates
HTML Certificate
CSS Certificate
JavaScript Certificate
jQuery Certificate
PHP Certificate
Bootstrap Certificate
XML Certificate
W3Schools is optimized for learning, testing, and training. Examples might be simplified to improve reading and basic understanding.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content.
While using this site, you agree to have read and accepted our terms of use, cookie and privacy policy. Copyright 1999-2019 by
Refsnes Data. All Rights Reserved.
Powered by W3.CSS.