SQL like syntax and SQL like Blur query

Source: Internet
Author: User

The LIKE operator is used to search for a specified pattern in a column in a WHERE clause.

Like operator
The LIKE operator is used to search for a specified pattern in a column in a WHERE clause.

SQL Like operator syntax
SELECT column_name (s) from Table_namewhere column_name as the original table (used in the example):
Persons table:

Id LastName FirstName Address City
1 Adams John Oxford Street London
2 Bush George Fifth Avenue New York
3 Carter Thomas Changan Street Beijing

Like operator instance
Example 1
Now, we want to select from the "Persons" table above the people who live in the city starting with "N":

We can use the following SELECT statement:

SELECT * from Personswhere city like ' N% ' tip: '% ' can be used to define wildcard characters (missing letters in the pattern).

Result set:
Id LastName FirstName Address City
2 Bush George Fifth Avenue New York

Example 2
Next, we want to select from the "Persons" table the people who live in cities that end with "G":

We can use the following SELECT statement:

SELECT * from Personswhere city like '%g ' result set:
Id LastName FirstName Address City
3 Carter Thomas Changan Street Beijing

Example 3
Next, we want to select from the "Persons" table the people who live in the city that contains "lon":

We can use the following SELECT statement:

SELECT * from Personswhere city like '%lon% ' result set:
Id LastName FirstName Address City
1 Adams John Oxford Street London

Example 4
By using the NOT keyword, we can select people residing in cities that do not contain "lon" from the "Persons" table:

We can use the following SELECT statement:

SELECT * from Personswhere '%lon% ' result set:
Id LastName FirstName Address City
2 Bush George Fifth Avenue New York
3 Carter Thomas Changan Street Beijing


Like operator
The LIKE operator is used to search for a specified pattern in a column in a WHERE clause.

SQL Like operator syntax
SELECT column_name (s)
From table_name
WHERE column_name like pattern hint: "%" can be used to define wildcard characters (missing letters in the pattern).
When searching for data in a database tutorial, you can use the SQL wildcard character.
SQL wildcard character
When searching for data in a database, the SQL wildcard character can override one or more characters.
SQL wildcard characters must be used with the LIKE operator.
In SQL, you can use the following wildcard characters:
Wildcard description% replaces one or more characters _ only one character [charlist] Word columns any single character [^charlist] or [!charlist] not Word


The LIKE operator is used to search for a specified pattern in a column in a WHERE clause.

Like operator

The LIKE operator is used to search for a specified pattern in a column in a WHERE clause.
SQL Like operator syntax
SELECT column_name (s) from table_name WHERE column_name like pattern
The original table (in the example):
Persons table: Id LastName FirstName Address City
1 Adams John Oxford Street London
2 Bush George Fifth Avenue New York
3 Carter Thomas Changan Street Beijing

Like operator instance
Example 1
Now, we want to select from the "Persons" table above the people who live in the city starting with "N": we can use the following SELECT statement: SELECT * from Persons WHERE town like ' N% '
Tip: "%" can be used to define wildcard characters (missing letters in the pattern).

Result set:
Id LastName FirstName Address City
2 Bush George Fifth Avenue New York

Example 2

Next, we want to select from the "Persons" table the people who live in cities that end with "G":

We can use the following SELECT statement:

SELECT * from Persons WHERE city like '%g '

Result set:
Id LastName FirstName Address City
3 Carter Thomas Changan Street Beijing

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.