SQL Like Operator
The LIKE operator is used
in a WHERE clause to search for a specified pattern in a column. Or used to
search for a specified pattern in a column.
SQL LIKE Syntax
SELECT
column_name(s) FROM table_name WHERE column_name LIKE pattern
|
LIKE Operator Example
“Persons” TABLE:
P_Id
|
LastName
|
FirstName
|
Address
|
City
|
1
|
Suhail
|
Osmani
|
Maharaj
Nagar
|
Sitapur
|
2
|
Maxwel
|
Tom
|
Biswan
|
Sitapur
|
3
|
Rahi
|
Ayon
|
Okhla
|
Delhi
|
SELECT
* FROM Persons WHERE City LIKE 's%'
|
Output:
P_Id
|
LastName
|
FirstName
|
Address
|
City
|
1
|
Suhail
|
Osmani
|
Maharaj
Nagar
|
Sitapur
|
2
|
Maxwel
|
Tom
|
Biswan
|
Sitapur
|
We use the following SELECT statement:
SELECT
* FROM Persons WHERE City LIKE '%r'
|
P_Id
|
LastName
|
FirstName
|
Address
|
City
|
1
|
Suhail
|
Osmani
|
Maharaj
Nagar
|
Sitapur
|
2
|
Maxwel
|
Tom
|
Biswan
|
Sitapur
|
We use the following SELECT statement:
SELECT
* FROM Persons WHERE City LIKE '%elh%'
|
P_Id
|
LastName
|
FirstName
|
Address
|
City
|
3
|
Rahi
|
Ayon
|
Okhla
|
Delhi
|
We use the following SELECT statement:
SELECT
* FROM Persons WHERE City NOT LIKE '%elh%'
|
P_Id
|
LastName
|
FirstName
|
Address
|
City
|
1
|
Suhail
|
Osmani
|
Maharaj
Nagar
|
Sitapur
|
2
|
Maxwel
|
Tom
|
Biswan
|
Sitapur
|
SQL Like Operator
Reviewed by Admin
on
04:24:00
Rating:
No comments: