About the first N Summary of oracle queries recently used the oracle database, it is obviously different from the previous SQL statements. Which of the following keywords cannot be used in top, in oracle, the following is a summary of the methods and experiences of querying the first N rows in oracle: www.2cto.com first in SQL2005: select top 10 * from table1; the first N statistical sorting can be achieved by associating order by and other conditions, in oracle, it is obvious that the first N statements of the following simple query are not executed according to this method (the first N records are displayed after sorting by statistics ): tested -- test passselect id from (select id, rownum as con from (select id from llt_org_info a order by id desc) where rownum <= 10) where con> = 1 then insert the SQL statement according to the following structure (test failed) -- Failed (error ORA_00907 missing right brackets) select. id, a.org _ code, a.org _ name, (select rownum as con from (select count (*) from llt_report B where B. send_org_id =. id) as org_count from llt_org_info a order by org_count desc where rownum <= 10) where con> 1 from SQL internal to external analysis: Layer 1: select count (*) from llt_report B where B. send_org_id =. id) as org_count from llt_org_info the statement shows the second layer of OK according to the number of statistics in the joined table: (select count (*) from llt_repo Rt B where B. send_org_id =. id) as org_count from llt_org_info a order by org_count desc where rownum <= 10) (test failed) The rownum obtained during oracle Parsing is the pseudo series that comes with the query, it is easy to identify a dataset, but it must be the second layer after the query result is determined: (select count (*) from llt_report B where B. send_org_id =. id) as org_count from llt_org_info a order by org_count desc) where rownum <= 10 in the statement: -- not passed (error ORA_00907 missing right brackets) select. id, a.org _ code, a.org _ name, (select rownum as c On from (select count (*) from llt_report B where B. send_org_id =. id) as org_count from llt_org_info a order by org_count desc) where rownum <= 10 where con> 1 first let's take a look at the tested SQL: select id, org_code, org_name, org_count from (select rownum rn,. * FROM (select id, org_code, org_name, (select count (*) from llt_report B where B. send_org_id = c. id) as org_count from Llt_org_Info c order by org_count desc) A WHERE R OWNUM <= 10) where rn> 0 re-analysis statement: No problem with the first layer of statistics, no problem after the second layer of sorting, however, after the second-level query, it is concluded that the oracle dataset redefined rownum For This dataset and the query result set is A new table. In this new table, an alias is created for the operation, so Layer 3: (select rownum rn,. * FROM (...........) A where rownum <= 10 Finally, based on the relevant display column, the outermost layer takes the query field Summary: oracle provides rownum for the pseudo series number, use rownum to sort the result set numbers to control the display of the First N data records.