This wildcards is used when we want to match a string pattern . And this can be do with the help of wildcards only .
In SQL there are two types of wildcards :
% : Percentage sign which represent 0 , 1 or more characters .
_ : Underscore which represent exactly one character .
Example :
Table name : Employee_Info
Id Employee_name Employee_Age Employee _Salary City
1 Mukesh 23 120000 Meerut
2 Ayush 24 200000 Baroda
3 Ishan 40 400000 Multan
4 Pranav 35 123,00000 Dehradun
5 Abhishek 26 800000 Mussoorie
6 Ravi 25 300000 Pauri-Garhwal
7 David 40 8000 Baghpat
Query : To select city where city start with M
select * from Employee_Info where City like ' M% ' ;
Output : All recods will come in which city is starting from letter M .
Id Employee_name Employee_Age Employee _Salary City
1 Mukesh 23 120000 Meerut
3 Ishan 40 400000 Multan
5 Abhishek 26 800000 Mussoorie
Query :
select * from Employee_Info where City like ' %n ' ;
Output : All recods will come in which city is ending with letter n .
Id Employee_name Employee_Age Employee _Salary City
3 Ishan 40 400000 Multan
4 Pranav 35 123,00000 Dehradun
Query :
select * from Employee_Info where City like ' %ss% ' ;
Output : All recods will come in which city containing the pattern " ss " .
Id Employee_name Employee_Age Employee _Salary City
5 Abhishek 26 800000 Mussoorie
Query : To select a city starting with any character followed by " tan "
select * from Employee_Info where City like ' _tan ' ;
Output : All recods will come in which city containing the pattern " tan " .
Id Employee_name Employee_Age Employee _Salary City
3 Ishan 40 400000 Multan
Query : To select a city starting with " M " followed by any character followed by " er " followed by any character followed by " ut "
select * from Employee_Info where City like 'M _er_ut ' ;
*Output : *
Id Employee_name Employee_Age Employee _Salary City
1 Mukesh 23 120000 Meerut
Query : To select a city starting with " M " , " B "
select * from Employee_Info where City like ' [MB]% ' ;
*Output : *
Id Employee_name Employee_Age Employee _Salary City
1 Mukesh 23 120000 Meerut
3 Ishan 40 400000 Multan
5 Abhishek 26 800000 Mussoorie
7 David 40 8000 Baghpat
0 Comment(s)