SQL LIKE Operator % and using pattern matching (LIKE Operator) -SQL

admin
By -
0

 


Before we start, you need to know about a few things: wildcards, underscore (_), percent (%), range, CONCAT, and string matching (LIKE and related concepts). Once you understand these, you’ll be able to work with operators easily.

  1. for example in like operator underscore ( __ ) represent single character , remember that cause later we need this to  replace and find specific values.
  2. for finding string or character values which start from specific character we using percent sign with ending it  e.g, LIKE 'Ind%'   here we got all countries which start with later IND .
  3. and for ending we can use same like LIKE '%Ind'

There is much more we can looking as question wise 

# What if same char repeat twice on same frequency or same time e.g. Moon has two o  at after one and another so  for like this situation we can do

LIKE '%oo%' ;   -using wildcard

# Finding length of ,matching records only 

get all countries name which length only have 4 so  this kind we using underscore 
and as you remembered underscore represent single character and here we looking for 4-char so  we need to use 4 -underscores

LIKE '____' ;

Note:- Underscore represent single character

# What we have to find where values contain two values anywhere in it?
Like Countries name where char repeat twice or more than?

 here we have to use underscore , wildcard both but specified pattern
e.g. Cambodia here you can see there two o  but  separated places

LIKE '%o__o%;

# What is name start with one letter and end with another sets of letters in that case what we do?
like country name start with C but ends with ia
like above.

LIKE 'C%ia';


#what if character repeats more then time of we know how many time 
e.g. three times?

LIKE '%a%a%a%' ;


This blog content would increase in future so stay tuned with it.

Post a Comment

0Comments

Put Your Thought or Query Here

Post a Comment (0)