Big SQL Energy Beginner Course: Lesson 8 Filtering w/ WHERE
Got BDE?⚡️
Hi BDEs! Welcome to Lesson 8 of the free Big SQL Energy Beginner Course⚡️ Today we’re learning about filtering data using the WHERE clause in SQL!
Return to Big SQL Energy Beginner homepage here to access the other lessons:
If you’re new here:
💁🏽♀️ Who Am I?
I’m Jess Ramos, the founder of Big Data Energy and the creator of the BEST SQL course and community: Big SQL Energy⚡️. Check me out on socials: 🔗LinkedIn, 🔗Instagram, 🔗YouTube, and 🔗TikTok. And of course subscribe to my 🔗newsletter here for all my upcoming lessons and updates— all for free!
⚡️ What is Big SQL Energy?
🔗Big SQL Energy Intermediate is an intermediate SQL course designed to solve real-world business problems hands-on using realistic data and a modern tech stack. You’ll walk away with 2 SQL portfolio projects, portfolio building guidance, access to the Big Data Energy Discord community, and lots of confidence for you upcoming coding interviews! You also get access to all monthly events including masterclasses, office hours, and guest speakers. This course is all of the most important things I’ve learned on the job as a Senior Data Analyst in tech who grew from a $72K salary to over a $150K salary. And now I’m sharing it with YOU! It’s more than just another course— it’s a challenging program designed to upskill your SQL to the intermediate level, get ready to ace your live coding interviews, and build connections in the data community through the Discord and events.
Lesson 8: Filtering w/ WHERE
Remember how in a previous lesson we talked about how real world tables can have millions of rows and we don’t want to pull in data we don’t need to improve query performance? Well, reducing rows with limit is a great way to “chop” the dataset and see a quick preview of the data. However, what if we want to be more selective about reducing our data and actually filter for certain values? For example, what if we want to pull all the order rows for a certain customer? Or maybe all the employees with a tenure over 1 year? Questions like this require using a filter on our dataset to pull the exact data we’re looking for based on specified conditions and values.
We filter rows in a dataset using the WHERE clause in SQL which goes right under SELECT and FROM! We can use WHERE to filter for conditions with strings (varchars), dates, numbers, and more. And we can use many kinds of operators to specify our conditions such as:
= is equal to
is greater than
is less than
>=is greater than or equal to
<= is less than or equal to
=! or <> is not equal to
Here are some examples with numbers:
select * from orders where price > 500;
select * from orders where price <= 500;
select * from orders where coupon > 0;
select * from orders where coupon != 0;
Here are some examples with dates:
select * from orders where order_date = '2024-08-05';
select * from orders where order_date >= '2024-08-05';
select * from orders where order_date <= '2024-08-05';
select * from orders where order_date != '2024-08-05';
Here are some examples with strings:
*** note that varchars (strings) MUST be in single quotes and are case sensitive
select * from orders where product_name = 'Laptop';
select * from orders where product_name != 'Mouse';
When working with conditions and operators in the WHERE clause, always be super careful about what is inclusive and exclusive in your condition. For example, adding an = (equals) to > (greater than) to make it >= (greater than OR equals to) changes the condition because it’s inclusive of the number you’re comparing to. Forgetting or accidentally adding an = to an operator can really mess you up and make you have holes in your logic or redundant logic— especially when you get further into the course and learn about using these in more advanced areas of SQL like with case statements. (We’ll learn the basics of case in this course, but head to my 🔗intermediate course for in-depth coverage of CASE statements and even how to create pivot tables in SQL— truly the best super power in data analytics!).
Filtering data with WHERE is one of the most basic data transformation steps you can do— you’re one step closer to building the result you’re looking for. I’ll see you in the next lesson!
If you’ve enjoyed the free BEGINNER Big SQL Energy course, grab my intermediate course. There are no deadlines or timelines for this course— you start and take as long as you want. It will take your beginner skills to the next level and get you ready to ace your interviews. DM me or email me at courses@bdeanalytics.com if you have questions on the intermediate course!
Return to Big SQL Energy Beginner homepage here to access the other lessons: