🚨 $100K in Sight: Follow Bitcoin’s Final Push Live! TRACK NOW

Code has been added to clipboard!

SQL AND, OR – Filtering Data Based on Two or More Conditions

Reading time 2 min
Published Aug 9, 2017
Updated Oct 3, 2019

SQL AND & OR Operators: Main Tips

  • The AND & OR operators filters records based on two or more conditions.
  • AND operator is satisfied if only all the conditions separated by AND are TRUE.
  • OR operator is satisfied if at least one of the conditions separated by OR are TRUE.

SQL AND Operator: Syntax

Shows a result if all the conditions with AND is TRUE.

Example
SELECT column_demo1, column_demo2, ...
FROM table_demo
WHERE condition_demo1 AND condition_demo2 AND condition_demo3 ...;
DataCamp
Pros
  • Easy to use with a learn-by-doing approach
  • Offers quality content
  • Gamified in-browser coding experience
  • The price matches the quality
  • Suitable for learners ranging from beginner to advanced
Main Features
  • Free certificates of completion
  • Focused on data science skills
  • Flexible learning timetable
Udacity
Pros
  • Simplistic design (no unnecessary information)
  • High-quality courses (even the free ones)
  • Variety of features
Main Features
  • Nanodegree programs
  • Suitable for enterprises
  • Paid Certificates of completion
edX
Pros
  • A wide range of learning programs
  • University-level courses
  • Easy to navigate
  • Verified certificates
  • Free learning track available
Main Features
  • University-level courses
  • Suitable for enterprises
  • Verified certificates of completion

SQL OR Operator: Syntax

Shows a result if any of the conditions with OR is TRUE

Example
SELECT column_demo1, column_demo2, ...
FROM table_demo
WHERE condition_demo1 OR condition_demo2 OR condition_demo3 ...;

Demo Database

This is demo example from the "Developers" table in the database:

ID Name City Country
1 Tom Kurkutis New York USA
2 Ana Fernandez London UK
3 Antonio Indigo Paris France
4 Aarav Kaelin Delhi India
5 Andrew Tumota Miami USA
6 Basma Zlata Miami USA

SQL AND & OR: Examples

In this example, we select all developers from the country "India" AND the city "Delhi", in the "Developers" table:

Example
SELECT * FROM Developers
WHERE Country='India' AND City='Delhi';

In this example, we select all developers from the city "London" OR "Paris", in the "Developers" table:

Example
SELECT * FROM Developers
WHERE City='London' OR City='Paris';

In this example, we select all developers from the country "USA" AND the city must be equal to "New York" OR "Berlin", in the "Developers" table:

Example
SELECT * FROM Developers
WHERE Country='USA' AND (City='New York' OR City='Miami');