top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

How does one select EVERY Nth row from a table In Oracle?

+1 vote
701 views
How does one select EVERY Nth row from a table In Oracle?
posted May 28, 2015 by Viswas Kumar

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Method 1: Using a subquery

    SELECT *
    FROM   emp
    WHERE  (ROWID,0) IN (SELECT ROWID, MOD(ROWNUM,4)
                         FROM   emp);

Method 2: Use dynamic views (available from Oracle7.2):

         SELECT *
    FROM   ( SELECT rownum rn, empno, ename
             FROM emp
           ) temp
    WHERE  MOD(temp.ROWNUM,4) = 0;

Method 3: Using GROUP BY and HAVING - provided by Ravi Pachalla

SELECT rownum, f1
FROM t1
GROUP BY rownum, f1 HAVING MOD(rownum,n) = 0 OR rownum = 2-n
answer May 29, 2015 by Arun Gowda
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...