top of page

Snack-Sized Data Basics
SQL - Filtering Intro

I created some quick set up steps you can use for the the upcoming lessons. It's quick way to create your table and add some data we'll be using to practice. Note that we added an extra column called absences to our previously used table.

Ok, let's get into filtering. 

​

Sometimes, you only want to return specific rows in a table instead of everything. For example, maybe you want the names and birthdates of students born this month so you can give them a little gift. Instead of pulling the entire table and checking each row manually, you can use SQL to return just those students. Neat, right?


Before we dive into how to do that in SQL, here’s a quick overview of the six types of filtering we’ll cover.

dataleaflet-filtering-overview.gif

​​

  • Comparison checks if a column's value is equal to, different from, greater than, or less than a specific value.

    • It uses =, !=, <>, <= and >=

    • An example would be if you wanted to get a list of students with more than two absences. 

  • Pattern​ is used to find text that matches a specific format.

    • It uses and _​​

    • An example would be if you wanted to get a list of students that have allergies that contain the word "berry". This will help pick up on allergies such as strawberry, blackberry, cranberry, and other types of berries. 

  • Range checks if a value falls between two values, including the endpoints.

    • It uses BETWEEN and AND

    • An example would be if you wanted to look for students who were born between January and March 2015. This will return all students born in January, February, and March.

  • List checks if a value matches any item from a list.

    • It uses IN

    • An example would be if you wanted to find all students with the last names Moore, Allen or Carter

  • Logical combines multiple conditions.

    • It uses ANDOR, NOT

    • An example would be if you wanted to find students whose first name is Chloe and last name is Young.

  • NULL Check finds rows where a column either has no value (NULL) or has one​​

    • It uses IS NULL and IS NOT NULL

    • An example would be if you wanted a list of students with NULL allergies. In our case, this won’t be necessary since we set all NULL allergies to 'None', but we’re covering NULL checks here nonetheless.​

​

​

In the next several lessons, we’ll go over SQL examples for each of these filtering types using the data from the quick set up.

bottom of page