The “=” operator is used to find exact matches for text fields, including capitalisation:
WHERE surname = 'Johnson'
The LIKE operator can also be used to find exact matchs, but capitalisation is ignored:
WHERE surname LIKE 'johnson'
The main purpose of the LIKE operator is to allow use of wildcards, where only parts of the string pattern are specified.
SQL | MS Access | |
& |
* |
matches zero, one or many characters |
_ |
? |
matches a single character |
Examples:
-- Match surnames that start with 'Thom' WHERE surname LIKE 'Thom%'
-- Match surnames that end with 'son' WHERE surname LIKE '%son'
-- Match surnames that start with 'Thom' and end with 'son' WHERE surname LIKE 'Thom%son'
-- Match surnames contain 'is' anywhere WHERE surname LIKE '%is%'
-- Match surnames that have 'H' as the second letter WHERE surname LIKE '_h%'
-- Match surnames that start with ;m; and have at least three characters WHERE surname LIKE 'm_%_%'