Filtering numbers

Intermediate SQL

Jasmin Ludolf

Data Science Content Developer, DataCamp

WHERE

  • WHERE filtering clause

Image showing a variety of colorful coats

Intermediate SQL

WHERE

WHERE color = 'green'

Image showing a variety of colorful coats and with a circle around the green coat

Intermediate SQL

WHERE with comparison operators

SELECT title
FROM films
WHERE release_year > 1960;
|title                |
|---------------------|
|Judgment at Nuremberg|
|Pocketful of Miracles|
|The Hustler          |
|The Misfits          |
...
Intermediate SQL

Comparison operators

SELECT title
FROM films
WHERE release_year < 1960;
|title                                          |
|-----------------------------------------------|
|Intolerance:Love's Struggle Throughout the Ages|
|Over the Hill to the Poorhouse                 |
|The Big Parade                                 |
|Metropolis                                     |
...
Intermediate SQL

Comparison operators

SELECT title
FROM films
WHERE release_year <= 1960;
|title                                          |
|-----------------------------------------------|
|Intolerance:Love's Struggle Throughout the Ages|
|Over the Hill to the Poorhouse                 |
|The Big Parade                                 |
|Metropolis                                     |
...
Intermediate SQL

Comparison operators

SELECT title
FROM films
WHERE release_year = 1960;
|title        |
|-------------|
|Elmer Gantry |
|Psycho       |
|The Apartment|
Intermediate SQL

Comparison operators

SELECT title
FROM films
WHERE release_year <> 1960;
|title                                          |
|-----------------------------------------------|
|Intolerance:Love's Struggle Throughout the Ages|
|Over the Hill to the Poorhouse                 |
|The Big Parade                                 |
|Metropolis                                     |
...
Intermediate SQL

Comparison operators

  • > Greater than or after
  • < Less than or before
  • = Equal to
  • >= Greater than or equal to
  • <= Less than or equal to
  • <> Not equal to
Intermediate SQL

WHERE with strings

  • Use single-quotes around strings we want to filter
SELECT title
FROM films
WHERE country = 'Japan';
|title            |
|-----------------|
|Seven Samurai    |
|Tora! Tora! Tora!|
|Akira            |
|Madadayo         |
|Street Fighter   |
...
Intermediate SQL

Order of execution

-- Written code:
SELECT item
FROM coats
WHERE color = 'green'
LIMIT 5;
  • Order of execution:
    • FROM coats
      
    • WHERE color = 'green'
      
    • SELECT item
      
    • LIMIT 5;
      
Intermediate SQL

Let's practice!

Intermediate SQL

Preparing Video For Download...