LIKE

It is used in the conditional part of a query. It replaces the „=“ operator. It is used when you want to use filtering with an undefined beginning/end of a string.

%     defines zero, one to an indefinite number of characters
_      defines exactly one character

Structure:
SELECT column_name
FROM table_name
WHERE column_name LIKE pattern;

 

Example1:

We have a table Customer with this data:

CustomerID Name Hair Salary
1 Alechandro brown 100
2 Katerina blonde 150
3 Lucie blonde 30
4 Thomas black 40
5 Theodor black 120
6 Thomassino black 99
7 Knor brown 50
8 Thor blonde 10
9 Lucie pink 70

 

SELECT name
FROM Customer
WHERE name LIKE 'T%';

 

Example2:

SELECT name
FROM Customer
WHERE name LIKE '%a';

 

Example3:

SELECT name
FROM Customer
WHERE name NOT LIKE '%a%';

 

Example4:

SELECT name
FROM Customer
WHERE name LIKE '%o%';

 

Example5:

SELECT name
FROM Customer
WHERE name LIKE '__or';

 

 

Leave a Comment

Your email address will not be published. Required fields are marked *