Loading...

Like operator is used with where clause in SQL Query. Like clause compares with an expression or a pattern using wildcard operators to match pattern in a column. 

Wildcard Operators
There are two wildcard operator that are used in Like Clause
  1. Percent sign (%): The percent sign represents zero, one or more than one character. 
  2. Underscore sign (_): The underscore sign represents only one character. If we use double underscore then this will represent two character and so on.

Here, we will see example of Like Clause
Consider, we have following Student Table

ID

Name

Age

Gender

1

Ram Kumar

12

M

2

Shyam Singh

15

M

3

Umakant

13

M

4

Rakesh Mishra

15

M

5

Rani Kumari

16

F

6

Vijay Kumar

12

M

7

Kishor Kant

11

M

8

Mamta Kumari

15

F



SQL Query with Percent sign 

Select * from Student where Name like 'RA%'

The above SQL Query will return all the records of student table where name start with "RA"

ID

Name

Age

Gender

1

Ram Kumar

12

M

4

Rakesh Mishra

15

M

5

Rani Kumari

16

F




SQL Query with Underscore sign 

Select * from Student where Name like '__M%'

The above SQL Query will return all the records of student table where name's third character is "M". Here we used double underscore.   

ID

Name

Age

Gender

1

Ram Kumar

12

M

8

Mamta Kumari

15

F