Select query with Like Operator

Select Query with Like Operator

Select * from where like ‘%RAJESH%’  escape ‘\’;

LIKE operator is used for pattern matching

_ stands for one character
% stands for muliple charcter

ESCAPE used for find _ or % in the string then you need to use escape clause

Example 1:

Search for middle name sharma in your employee table

select * from employee where employee_name like ‘%SHARMA%’ ;

Example 2:

Search for first character not know:

Select * from employee where employee_name like ‘_SHARMA’

It will give you result like ASHARMA and KSHARMA It will check only for first character.

Example 3:

If you data having _ in the value of that column suppose email id column having _  as data

select * from employee where email_id like ‘%\_sharma%’ escape ‘\’;

It will take _ as data due to escape clause used in it.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.