So that's the basics.
But there's another wildcard character that I'll show you which is the underscore.
So here I have a really weird query.
This is for underscores in a row they will have to trust me that it's four.
And it was hard to tell what this will do.
So we're searching stock quantity which is a number and we're trying to find where it's like for underscores
and basically an underscore is a wildcard to specify exactly one character any character but exactly
one.
So four of them in a row is saying I want to find where the stock quantity is for characters long.
So let me show you why we might want to do that.
Why do a select stock title and stock quantity from books just like that.
You can see that we have Star quantity of to her sorry two digit two tickets 32 43 three.
She is giving me a tough time.
Digits 154.
And then this great book linking in the bardo has a thousand copies in stock is brand new.
People don't know about it yet.
They're not buying it.
I'm sure people will buy it soon though.
Once Of course they they realize what a great book it is.
So if I wanted to select books where stock quantity is four digits long I could use that wild card.
So let me just say that again.
So select title and stock only from books where stock on or the like.
And all I have to do so just to clarify if I did this that wild card just means anything.
So that's going to give us everything.
And if I do four of them it doesn't make a difference.
That's not saying four characters.
That's just four different ways of saying anything at all.
It could be nothing.
It could be a thousand characters it doesn't matter.
So by adding underscores that's for there you'll see I get Lincoln in the bardo or I could do two underscores
and I only get the two digit stock quantities.
Now that's not to say the only time you use underscores is when you're trying.
Yes.
Blue is my cat.
Are you going to say hi.
She's now sitting on the computer.
OK.
So back to where I was.
Get this cat hair out of here.
The underscore is not only used and actually it's not even primarily used for counting digits like that
but it's a way of specifying exactly one character.
Like I said Let's say that we're working with phone numbers and in the US they might look something
like this.
So we have an area code in parentheses and then three digits dash four digits.
And if we wanted to match that pattern we would have something that looks like this like and we'd have
a first print to see and if we just put this wildcard there that's going to say any number any letters
whatever it is in between those parentheses but we're actually looking for three digits and then another
three digits after that parentheses.
Then a dash and then four digits.
So basically we have these two wild cards at the end of the day present sign which means anything or
nothing.
And then underscore which is exactly one thing.
And you can chain them together to match patterns then that brings up another question which is but
what if I'm searching for a book that has a percent sign in it.
How would I do that.
And you may have noticed that I expertly planted a book title with the percent sign and I was thinking
ahead for once.
How would we select that.
Or there's also a book title that it's not so creative It has an underscore in it.
How would I select that one.
If these characters are special wildcard characters how do I actually search for the exact character
percent side or the exact character underscore.
And the answer is actually pretty straightforward.
We use what's known as an escape character.
In this case I always forget which one is backwards and forwards slash but whichever slash This is the
one over the turkey.
Pretty sure that his backslash so backslash percent signed is going to match a percent sign.
So this entire thing right here is basically saying percent sign.
Likewise with underscores backslash underscore is the escape character.
So let's put that into practice.
Let's try it out.
So a select title from books and we'll just do that first all and you'll see we've got 10 percent happier
and then fake under scorebook.
So let's start with 10 percent happier.
So I want to select title from books from books where title like and just I mean this should be clear
right now.
But if we tried to do this that's not going to work that's going to give us everything.
But if I tried to say okay percent signed that means anything and then a percent signed and then anything
afterwards that's not going to work either because that's basically just three different ways of saying
anything at all in the title.
So that's where we need our backslash.
Now you could read this as you could condense this to say exactly a percent sign 1 percentage sign anything
before anything after.
And there we go.
That's how we get 10 percent happier.
Same thing with the underscore.
I won't go through that whole routine again.
We just replaced that backslash present with backslash underscore and that gives us fake book.
All right.
So that's all there is to like for now.
It's very very useful.
We'll be using it quite a bit in this course.
It's probably one the most commonly used things in my school are in school when doing queries.
In all likelihood you won't be matching percent signs or underscores all that often but you'll be doing
things like this all the time where you're using the percent wildcard and the underscore wildcard to
match patterns.
OK.
Next up exercise is.