Oracle queries the top five data

Source: Internet
Author: User

Oracle does not support top N

SELECT * FROM (SELECT * to T_weixin_homework ORDER by SUBSTR (hometitle,0,10) desc) where rownum<=5 order by rownum

Our main discussion today is the actual operation of Oracle's implementation of SELECT TOP N, the following is an introduction to its specific operation, I hope you will have something to gain.

AD:2014WOT Global Software Technology Summit Beijing Station course video release

The following article is mainly about how to implement select Top N in Oracle, we mainly use an example of the way to lead the implementation of SELECT Top N of Oracle, the following description of the specific content of the article, I hope you will have some gains.

1. Implementing select TOP N in Oracle

Because Oracle does not support the SELECT top statement, the query for select top n is often implemented in Oracle with the combination of order by and RowNum.

To put it simply, Oracle implements the Select TOP N method as follows:

SELECT Column Name 1 ... Column name n from

(SELECT column Name 1 ... Column name n from table name ORDER by column name 1 ... Column name N)

WHERE ROWNUM <= N (number of extracted records)

    1. ORDER by ROWNUM ASC

Here is an example to illustrate briefly.

Customer table Customer (Id,name) has the following data:

ID NAME

First

Second

Third

Forth, Geneva

Fifth

Sixth

Seventh

Eighth

Ninth

Ten Tenth

Last

The SQL statement for the first three customers is drawn according to the letter of name as follows:

    1. SELECT * FROM
    2. (SELECT * from CUSTOMER ORDER by NAME)
    3. WHERE ROWNUM <= 3
    4. ORDER by ROWNUM ASC

The output is:

ID NAME

Eighth

Fifth

First

The above-mentioned content is a description of the method of implementing Select TOP N in Oracle, and hopefully will give you some help in this regard.

Oracle queries the top five data

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.