Quantcast
Viewing latest article 4
Browse Latest Browse All 17

Answer by Vlad Mihalcea for How do I limit the number of rows returned by an Oracle query after ordering?

SQL Standard

Since version 12c Oracle supports the SQL:2008 Standard, which provides the following syntax to limit the SQL result set:

SELECT    titleFROM    postORDER BY    id DESCFETCH FIRST 50 ROWS ONLY

Oracle 11g and older versions

Prior to version 12c, to fetch the Top-N records, you had to use a derived table and the ROWNUM pseudocolumn:

SELECT *FROM (    SELECT        title    FROM        post    ORDER BY        id DESC)WHERE ROWNUM <= 50

Viewing latest article 4
Browse Latest Browse All 17

Trending Articles