The LIKE operator in SQL is used with the WHERE clause to get a result set that matches the given string pattern.
There are two wildcards often used with the LIKE operator,
- % (percent sign) - represents zero, one, or multiple characters
- _ (underscore sign) - represents one, single character
LIKE Operator Syntax
SELECT columnName,...
FROM tableName
WHERE columnName LIKE 'pattern';
FROM tableName
WHERE columnName LIKE 'pattern';
Example of SQL LIKE operator & Wildcards
SELECT * FROM Company
WHERE CompanyName LIKE 'Microsoft';
WHERE CompanyName LIKE 'Microsoft';
2. SQL Statement selects all Company with CompanyName that have value "M" at the first position
SELECT * FROM Company
WHERE CompanyName LIKE 'M%';
3. SQL Statement selects all Company with CompanyName that have value "soft" at the end
SELECT * FROM Company
WHERE CompanyName LIKE '%soft';
4. SQL Statement selects all Company with CompanyName that have value "web" at any position
SELECT * FROM Company
WHERE CompanyName LIKE '%web%';
5. SQL Statement selects all Company with CompanyName that have value "o" at second position
SELECT * FROM Company
WHERE CompanyName LIKE '_o%';
6. SQL Statement selects all Company with CompanyName that have value "g" at first position and value "e" as last position
SELECT * FROM Company
WHERE CompanyName LIKE 'g%e';
0 comments:
Post a Comment
Please do not enter any spam link in the message box.