A brief explanation of SQL wildcard related knowledge

Source: Internet
Author: User
You can use the SQL wildcard character when searching for data in a database, and this article will explain its knowledge.

You can use SQL wildcard characters when searching for data in a database.

SQL wildcard characters

The SQL wildcard can override one or more characters when searching for data in a database.

SQL wildcard characters must be used with the LIKE operator.

In SQL, you can use the following wildcard characters:

Use a% wildcard character

Example 1

Now, we want to choose from the "Persons" table above for people living in cities that start with "Ne":

We can use the following SELECT statement:

SELECT * from Personswhere city like ' ne% '

Example 2

Next, we want to select from the "Persons" table the people who live in cities that contain "Lond":

We can use the following SELECT statement:

SELECT * from Personswhere city like '%lond% '

Using _ Wildcard characters

Example 1

Now, we want to select the first character of the name from the "Persons" table above and then the person who is "eorge":

We can use the following SELECT statement:

SELECT * from Personswhere FirstName like ' _eorge '

Example 2

Next, we want the last name of the record selected from the "Persons" table to start with "C", then an arbitrary character, then "R", then any character, then "ER":

We can use the following SELECT statement:

SELECT * from Personswhere LastName like ' c_r_er '

Using [charlist] wildcard characters

Example 1

Now, we would like to select from the "Persons" table above the person who lives in the city that begins with "A" or "L" or "N":

We can use the following SELECT statement:

SELECT * from Personswhere city like ' [aln]% '

Example 2

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

We can use the following SELECT statement:

SELECT * from Personswhere city like ' [! aln]% '

This article on the wildcard is related to the explanation, more learning materials to pay attention to the PHP Chinese network can be viewed.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.