SQL Basic
SQL Advanced
SQL Functions
| SQL Like |
|
The LIKE operator is used in a WHERE clause to search for a specified pattern in a column. The LIKE OperatorThe LIKE operator is used to search for a specified pattern in a column. SQL LIKE Syntax
LIKE Operator ExampleThe "Persons" table:
Now we want to select the persons living in a city that starts with "s" from the table above. We use the following SELECT statement:
The "%" sign can be used to define wildcards (missing letters in the pattern) both before and after the pattern. The result-set will look like this:
Next, we want to select the persons living in a city that ends with an "s" from the "Persons" table. We use the following SELECT statement:
The result-set will look like this:
Next, we want to select the persons living in a city that contains the pattern "tav" from the "Persons" table. We use the following SELECT statement:
The result-set will look like this:
It is also possible to select the persons living in a city that NOT contains the pattern "tav" from the "Persons" table, by using the NOT keyword. We use the following SELECT statement:
The result-set will look like this:
|
SQL Like