How can we retrieve alternate records from a table in Oracle?

We can use rownum and MOD function to retrieve the alternate records from a table.

  • To get Even number records:SELECT *
    FROM (SELECT rownum, ID, Name
    FROM Employee)
    WHERE MOD(rownum,2)=0
  • To get Odd number records:SELECT *
    FROM (SELECT rownum, ID, Name
    FROM Employee)
    WHERE MOD(rownum,2)=1
Read the full book at www.amazon.com
Posted in SQL, SQL Interview Questions

Leave a Reply

Your email address will not be published. Required fields are marked *

*