SQL LIKE is very important to php, so this article will explain it
LIKE Operator
The LIKE operator is used to search a specified pattern in a column in the WHERE clause.
SQL LIKE operator syntax
SELECT column_name(s) FROM table_name WHERE column_name LIKE pattern
LIKE operator example
Example 1
Now, we want to select residence from the "Persons" table above People in cities starting with "N":
We can use the following SELECT statement:
SELECT * FROM Persons WHERE City LIKE 'N%'
Tip: "%" can be used to define the wildcard character (pattern missing letters).
Example 2
Next, we want to select people from the "Persons" table who live in cities ending with "g":
We can use the following SELECT statement:
SELECT * FROM Persons WHERE City LIKE '%g'
Result set:
Example 3
Next, we want to select people living in cities containing "lon" from the "Persons" table :
We can use the following SELECT statement:
SELECT * FROM Persons WHERE City LIKE '%lon%'
Example 4
By using the NOT keyword, we can select from the "Persons" table living in a country that does not contain " lon" people in the city:
We can use the following SELECT statement:
SELECT * FROM Persons WHERE City NOT LIKE '%lon%'
This article provides a relevant explanation of SQL LIKE. For more learning materials, please pay attention to php Chinese You can watch it online.
Related recommendations:
Explanation on the SQL TOP clause
About the analysis of the SQL SELECT DISTINCT statement
Related knowledge about SQL SELECT statement
The above is the detailed content of An explanation of the SQL LIKE operator. For more information, please follow other related articles on the PHP Chinese website!