Previous | Home | Next |
Using String Operator
String operator provide a LIKE keyword to search for a string with wild card mechanism.
Dtatype | Range |
% | Represents any string of Zero or more character |
_ | Represent the single character |
[] | Represent any single character within the specified range |
[^] | Represent any single character not within the specified range |
Example:
SELECT * FROM titles WHERE type LIKE 'bus%'
Return all attribute from the titles table in which the type starts with 'bus'
SELECT * FROM titles WHERE type LIKE 'bu_'
Return all attribute from the titles table in which the type of book is the three character long and starts with 'bu'. Increase the '_' keyword increase the number of characters.
SELECT * FROM titles WHERE type LIKE 'b[us]%'
Return all attribute from the titles table in which the type of book is starts with 'b' and contain u and s on the second position followed by any number of character.
SELECT * FROM titles WHERE type LIKE 'b[^s]%'
Return all attribute from the titles table in which the type of book is starts with 'b' and does not contain s on the second position followed by any number of character.
Some Example
Expression | Returns |
LIKE '%ty%' | All names that have the letters 'ty' in them |
LIKE '_ty' | All three letter names ending with 'ty' |
LIKE '[AD]%' | All name that begin with "A" or "K" |
Previous | Home | Next |