Use LIKE to find matching strings and substrings
suggest changeSee full documentation on LIKE operator.
This example uses the Employees Table from the Example Databases.
SELECT *
FROM Employees
WHERE FName LIKE 'John'
This query returns Employee #2, John Johnson. Employee #1 is James Smith, so an exact match on John does not return him. LIKE without a wildcard is still a match of the whole string, and case depends on the collation.
SELECT *
FROM Employees
WHERE FName like 'John%'
Adding % allows you to search for a substring:
John%- will return any Employee whose name begins with ‘John’, followed by any amount of characters%John- will return any Employee whose name ends with ‘John’, preceded by any number of characters%John%- will return any Employee whose name contains ‘John’ anywhere within the value
In this case, the query will return Employee #2 whose name is ‘John’ as well as Employee #4 whose name is ‘Johnathon’.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents