Imagine you have a list of user accounts, and you've forgotten the last character of a specific username. Let's say, you know the username starts with nick24 but has another character you cannot recall.
Here is a sample of the data you looking at:
| user_id | username |
|---|---|
| 1 | nick249 |
| 2 | nick2412 |
| 3 | nick2423 |
From here, you know that you need to find that user_id number 1. But of course, you are dealing with thousands of data and you don't want to do that manually! Here is where you need to use the underscore.
SELECT *
FROM users
WHERE username ILIKE 'nick24_';
This query looks for usernames that match the pattern nick24_. The underscore in nick24_ means any single character, so it matches nick249 or any other username that has one single character after nick24.
Here are more cool tricks using Underscores:
Got it on the first try? 🌟 Awesome! Time to start practicing. If not, no stress! 🙌 Take it easy and give it another read. SQL can be tricky, but you'll get there with a bit of practice.
😊 Keep going!
