Explanation of SQL wildcard related knowledge

jacklove
Release: 2023-03-25 15:20:01
Original
1920 people have browsed it

When searching for data in the database, you can use SQL wildcards. This article will explain the relevant knowledge in detail.

You can use SQLwildcardswhensearching for data in adatabase.

SQL Wildcards

SQL wildcards can replace one or more characters when searching for data in a database.

SQL wildcards must be used with the LIKEoperator.

In SQL, you can use the following wildcards:

Use the % wildcard character

Example 1

Now, we want to extract data from the "Persons" table above Select people living in cities starting with "Ne":

We can use the following SELECT statement:

SELECT * FROM Persons WHERE City LIKE 'Ne%'
Copy after login

Example 2

Next, we want to start with " Persons" table to select people living in cities containing "lond":

We can use the following SELECT statement:

SELECT * FROM Persons WHERE City LIKE '%lond%'
Copy after login

Use _ wildcard

Example 1

Now, we want to select people whose first character is "eorge" after the first character of their name from the above "Persons" table:

We can use the following SELECT statement:

SELECT * FROM Persons WHERE FirstName LIKE '_eorge'
Copy after login

Example 2

Next, we want the last name of this record selected from the "Persons" table to start with "C", then any character, then "r", then any character, then "er":

We can use the following SELECT statement:

SELECT * FROM Persons WHERE LastName LIKE 'C_r_er'
Copy after login

Use [charlist] wildcard

Example 1

Now, we want to select people whose cities start with "A" or "L" or "N" from the "Persons" table above:

We can use the following SELECT statement :

SELECT * FROM Persons WHERE City LIKE '[ALN]%'
Copy after login

Example 2

Now, we want to select people whose cities do not start with "A" or "L" or "N" from the "Persons" table above:

We can use the following SELECT statement:

SELECT * FROM Persons WHERE City LIKE '[!ALN]%'
Copy after login

This article provides a relevant explanation of wildcards. For more learning materials, please pay attention to the php Chinese website.

Related recommendations:

Explanation about the SQL LIKE operator

Explanation about the SQL TOP clause

About the analysis of SQL SELECT DISTINCT statement

The above is the detailed content of Explanation of SQL wildcard related knowledge. 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!