SQL Advanced Statement

Source: Internet
Author: User

TOP 2* FROM Persons


TOP 50 PERCENT* FROM Persons



Example 1

Now, we want to choose from the "Persons" table above for people living in cities that start 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).

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 '






Example 3

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

We can use the following SELECT statement:

SELECT * from Personswhere city like '%lon% '



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 City does like '%lon% '








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:

wildcard characters Description
% Override one or more characters
_ Replaces only one character
[Charlist] Any single character of the word columns

[^charlist]

Or

[!charlist]

Any single character that is not in the word columns

In operator

The in operator allows us to specify multiple values in the WHERE clause.

SQL in syntax
SELECT column_name (s) from Table_namewhere column_name in (value1,value2,...)


Between operator

operator between ... and selects a range of data between two values. These values can be numeric, text, or date.

SQL between syntax
SELECT column_name (s) from Table_namewhere Column_namebetween value1 and value2








SQL Advanced Statement

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.