query

SQL Tutorial - 23: The LIKE Operator and Wildcard Characters



Sharing buttons:

hello guys what my channel this is the

twenty-third tutorial in this course and

in this video we'll be talking about the

like operator see you've seen the micro

creator once when we have the tutorial

on logical operators I mentioned it and

you also saw a couple of applications of

red in the MySQL environment but you

know I thought that there should be one

separately toriel on the like operator

and the wildcard characters are

associated with the like red and so

there is a and the like operator as you

guys know is used to compare our values

similar values in a table in the

database and what I mean by this is if

you have some value that you want to

place in your where clause

and you want to compare that value with

the values that are present in you know

your table in the database then you

would have to use a like credit to make

such comparisons and the like operator

is used with wildcard characters and

there are two wild-card characters that

you can use the first one is the

percentage symbol in the second one is

the underscore character the percentage

symbol is a substitution for zero one or

many characters whereas the underscore

character stands for one character

number and the syntax of the vibrator is

pretty simply part of select keyword

first and then Colin list and then drawn

keyword and the name of the table from

which you are putting your data and then

an optional weight loss through which

you would you know make the comparison

using the like operator right and even

if you are making comparisons between

numeric values you have to place your

values within single quotes and this is

different because when you use the

assignment operator to make direct

comparisons or record any test we do not

put our new values within single quotes

but we're using the like operator even

if you are making comparisons between

numbers you have to make sure that the

values that are there the word laws are

between single quotes and this would be

clear when we check out examples in the

mask environment so let's check out few

examples but got my workbench air and

just as we have in the past tutorials we

are going to work the employee table in

the test database and let me show you

guys the data that I have in the table

at the moment so to show the data I want

the executi select start worry name the

table is employee semicolon when I press

control enter I see that I have 17

records in the table the first row has

the value of the ID field as 1900 and

the last row has the value of 1967 total

there are 17 fees in the table and the

last record

well it wasn't present in the table till

this tutorial I added this row to this

table you know for the sake of this

result because I wanted one employee to

have this of an email account on hotmail

right and you understand why I did that

in just a minute so you know let's start

with this in fact you know suppose I

want to find out the you know name or in

fact all the information about the

employee who's got this of an email

address at hotmail then the query that

would be I'll type in select first right

and then I put in the ass example

because I want to pull out all

information and then the name of the

table after the strong keyword which is

employee and then type in where and then

since I want the comparison to be made

more with the value that's telling the

email field I'll type in email here

first right and then I type in the light

keyword because I would not be usually

like operator to make the comparison

between the value that's there in the Y

that I'm going to put within single

quotes and since you know I just want to

know you know who is got his or her

email address at hotmail I am NOT

concerned with the initial part of the

email address or the last part of the

email address and the last part I know

that after hotmail

we're going to have calm but you know

I'll just type in hotmail here and I

will put in a percentage character after

hotmail and and put in percentage

character for Hortman so what this is

going to do is it's going to instruct

SQL that get me all the records you

don't care what the first part of the

email addresses more the last part of

the email addresses we just want to make

sure that you know the word hot man is

there in the email address I put in a

semicolon at the end terminated

statement when I execute it I see that I

have purchased one employee in the table

who has you know his email address

registered at heart meds or the name of

the employees job and the IDS 19:16 is

the row that I added right and let's say

you want to also find out you know all

the employees who are in their twenties

right so since in this case we would be

working with the age column I would

replace men with age and you know since

you want to know employees were greater

than four years or in less than twenty

years old

we can use the or and logical operators

to you know generate this condition but

if you want to use the like greater than

what you do is within single quotes

important too and then you put an

underscore character after also the

underscore character as I mentioned when

you were looking through the PowerPoint

that the underscore character

substitutes one character number so in

this case it's a substitution for one

number so we don't care what the value

after two is if it's 21 or 22 or 23 or

29 but the first digit in the age has to

be two so as long as the first did it is

to you know the row is going to be

displayed in the result set

so when I execute this query I see that

all these employees have their age in 20

so John is 26 years old nick is 25 Dave

is 27 minus 21 so on and so forth and

the last example that we're going to

check out in this example we'll use the

underscore character as well as the

portion designee so suppose you want to

find out

you know information about employees you

know who have oh the alphabet Oh as the

second character in their names right so

it's obviously we work with the name

field and type in the like keyword and

then within single quotes the value

which I'm going to make my comparisons

is going to be I'd put in the underscore

characters first then the alphabet Co

and then we person date simply so what

this is going to do is it's going to

instruct SQL that the first character in

the name will be anything right it will

be BS

pee-eww whatever the second alphabet or

the second character has to be the

alphabet oh and the rest of the name

could also have as many characters or

you know whatever character so we are

not concerned about the last part of the

name or the first act of the name would

be concerned about the second alphabet

which has to be oh right I totally

semicolon when I execute this query I

see that I get all these names in the

result set so John you know you can see

that John's a name as low as I can

gagged Rogers name as also second

character Howard's name is always in

character so so on and so forth so

that's it about the dive operator I hope

you guys had fun watching this tutorial

and please subscribe to my channel in

case you have already and I'll see you

in the next tutorial