The SQL like clause is used to look for the values which are similar to the values in the table with the help of wildcard operators. We have two types of wildcard operators:
1. "% - percent sign
2. _- underscore
Syntax:
SELECT FROM table-name
WHERE column LIKE ' XX%';
or
SELECT FROM table-name
WHERE column LIKE '%XX%';
or
SELECT FROM table-name
WHERE column LIKE '_XX';
or
SELECT FROM table-name
WHERE column LIKE '_XX_';
The only difference between these two wildcard operators is that former is used to represent 0,1 or multiple characters whereas the latter is used to represent a single number or character.
Although, these symbols can be used in many different combinations:
Query
|
Description
|
WHERE name LIKE 'A%'
|
Look into the column name which starts with 'A'
|
WHERE name LIKE '%N'
|
Look into the column name which ends with 'N'
|
WHERE name LIKE '%AN%'
|
Look into the column name which contains the combination of 'AN' in middle.
|
WHERE id LIKE '_00'
|
Finds id that have 00 in the second and thord position.
|
WHERE salary LIKE '2_%_%'
|
Finds salary which starts with 2 and are alteast 3 characters in lenght.
|
0 Comment(s)