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)
- 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:
- SELECT * FROM
- (SELECT * from CUSTOMER ORDER by NAME)
- WHERE ROWNUM <= 3
- 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