An explanation of the SQL LIKE operator

Robert De Niro
Release: 2023-03-25 15:18:02
Original
1989 people have browsed it

SQL LIKE is very important tophp, so this article will explain it

LIKEOperator

The LIKE operator is used tosearcha 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
Copy after login

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%'
Copy after login

Tip: "%" can be used to define thewildcard 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'
Copy after login

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%'
Copy after login

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%'
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!