Showing posts with label Incremental Queries. Show all posts
Showing posts with label Incremental Queries. Show all posts

Monday, March 16, 2015

Different ways to fetch Incremental data from oracle tables

Incremental Query 
Method 1: Fetch the record between two records
SELECT  * FROM (SELECT  emp.*, rownum rn FROM emp ) WHERE  rn between 2 and 5;

Method 2: Fetch the record between two records
SELECT  * FROM (SELECT  q.*, rownum rn FROM( SELECT  * FROM  emp ) q ) WHERE  rn BETWEEN 2 AND 5;

Method 3: Fetch the last record form table
SELECT  * FROM (SELECT  q.*, rownum rn FROM (SELECT * FROM  emp) q ) WHERE  rn=(select max(rownum) from emp);