Submitted Questions

  • Fetch Alternate Rows

    How to fetch alternate rows from the table?

    Ram

    • Feb 6th, 2013

    Code
    1. SELECT * FROM EMP
    2. WHERE (ROWID,1) IN (SELECT ROWID,MOD(ROWNUM,2) FROM EMP);
    3.  
    4. OR
    5.  
    6. SELECT * FROM (SELECT EMP.*,ROWNUM K FROM EMP)
    7. WHERE MOD(k,2)=0;

    Millar

    • Jul 26th, 2012

    Code
    1. SELECT * FROM table_name WHERE mod(primary_key_column,2)=0 --to find even rows in a table
    2.  
    3. SELECT * FROM employees WHERE mod(employee_id,2)=0 --to find even rows in a table
    4.  
    5. SELECT * FROM employees WHERE mod(employee_id,2)=1 --to find odd rows in a table