Big SQL Energy Beginner Course: Lesson 13 Wildcards
Got BDE?⚡️
Hi BDEs! Welcome to Lesson 13 of the free Big SQL Energy Beginner Course⚡️ Today we’re learning about Wildcards 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 13: Wildcards
Have you ever searched for something, and you’re not exactly sure what it looks like? Or maybe you’re searching for something that follows a certain pattern, and you aren’t too picky outside of that. Well this is where wildcards come into play! Wildcards are placeholders that hold the place of 0 or more characters so you can clearly define a pattern in your string data you’re looking for. Wildcards are a placeholder in your data that can take the place of anything or nothing, and they’re denoted with a %. (There’s another variation as well that we’ll learn in another lesson!)
Wildcards are used with the LIKE operator, which compares a value to the defined string pattern with a wildcard. Here’s an example of searching for customers with a first name starting with D:
select
*
from
orders
where
customer_first_name like 'D%'
We can compare each customer_first_name value to the pattern using the LIKE operator. We can define the pattern by using a string that starts with D as the first character (since that’s the requirement we want to set and lock in) and finish the pattern with a wildcard, or a %. The wildcard portion can take the place of 0 or more characters, so any customer with a first name of D or Daniel or David or Drew or Da or Dinvivnionvovo will match the pattern and show up. Any number of characters in the % spot after D will match the pattern.
Please note that the like operator is CASE SENSITIVE when comparing strings, so the following 2 queries will produce different results:
select
*
from
orders
where
customer_first_name like 'D%' ;
select
*
from
orders
where
customer_first_name like 'd%' ;
If you don’t pay attention to capital letters, you may get incorrect results or not find what you’re looking for. It’s also possible to combine multiple conditions with wildcards like this:
select
*
from
orders
where
customer_first_name like 'D%'
and customer_last_name like 'F%' ;
This will pull all customers who have a first name starting with D and a last name starting with F (capital D & F since like is case sensitive!). And you can put the wildcard in the middle of a string as well:
select
*
from
orders
where
customer_first_name like '%n%'
This will pull all customers that contain an n in their first name— including those who start or end with n as well too since wildcards can represent 0 characters! Here’s an example of using wildcards to search for a string that ends with s. Searching for string patterns with the wildcard at the BEGINNING of a string is not great for optimization (we’ll cover this more in depth in my 🔗intermediate course), so only use it if actually necessary.
select
*
from
orders
where
customer_first_name like '%s'
Here’s a query searching for all customers whose first name starts with Jess and last name starts with R:
select
*
from
orders
where
customer_first_name like 'Jess%'
and customer_last_name like 'R%' ;
This will return all customers with a first name: Jess, Jessica, Jessie, Jessenia, etc. and a last name starting with R. Looks like Jess Ramos makes the cut here 😉
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: