Skip to main content

Multiple Criteria

Updated Aug 23, 2019 ·

Overview

To enhance our filters using WHERE, we can add multiple criteria with the keywords OR, AND, and BETWEEN. These help us refine our queries more effectively.

  • OR: Filters when at least one condition is true.
  • AND: Filters when all conditions are true.
  • BETWEEN: Filters values within a specific range.

We'll use the films table for the examples:

idtitlerelease_yearcountrydurationlanguagecertificationgrossbudget
1Inception2010USA148EnglishPG-13829895144160000000
2Parasite2019South Korea132KoreanR25759015211400000
3The Godfather1972USA175EnglishR2461209866000000
4Amélie2001France122FrenchR17420000010000000
5Coco2017USA105SpanishPG807082196175000000

OR Operator

To filter films released in either 2010 or 2019:

SELECT title, release_year
FROM films
WHERE release_year = 2010 OR release_year = 2019;

Output:

titlerelease_year
Inception2010
Parasite2019

AND Operator

To filter films that are in English and have a certification of PG-13:

SELECT title, language, certification
FROM films
WHERE language = 'English' AND certification = 'PG-13';

Output:

titlelanguagecertification
InceptionEnglishPG-13

Combining AND and OR

To filter films released in 2010 OR 2019, AND with a certification of either PG-13 or PG:

SELECT title, release_year, certification
FROM films
WHERE (release_year = 2010 OR release_year = 2019)
AND (certification = 'PG-13' OR certification = 'PG');

Output:

titlerelease_yearcertification
Inception2010PG-13

BETWEEN Keyword

To filter films released between 2000 and 2010:

SELECT title, release_year
FROM films
WHERE release_year BETWEEN 2000 AND 2010;

Output:

titlerelease_year
Inception2010
Amélie2001

Combining BETWEEN, AND, and OR

To filter films released between 2000 and 2010 and from the USA:

SELECT title, release_year, country
FROM films
WHERE release_year BETWEEN 2000 AND 2010
AND country = 'USA';

Output:

titlerelease_yearcountry
Inception2010USA