Display Odd/ Even number of records

Odd number of records:
select * from emp where (rowid,1) in (select rowid, mod(rownum,2) from emp);
Output:-
1
3
5
Even number of records:
select * from emp where (rowid,0) in (select rowid, mod(rownum,2) from emp)
Output:-
2
4
6

Showing Answers 1 - 6 of 6 Answers

Jayakumar M

  • Nov 8th, 2005
 

ODD ROWS:-

SELECT * FROM emp WHERE ROWID IN ( SELECT DECODE(MOD(ROWNUM,2),1,ROWID) FROM emp );

EVEN ROWS:-

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

  Was this answer useful?  Yes

nileshsingh

  • May 18th, 2006
 

TO display the odd number to record

select * from table_name where (rowid,1) in ( select rowid,mod(rownum,2) from table_name )

to display the even number of record

select * from table_name where (rowid,0) in ( select rowid,mod(rownum,2) from table_name );

  Was this answer useful?  Yes

Prabhu Srinivasan

  • Aug 9th, 2006
 

hi,

   This Query fetches wrong number of values

FOR DISPLAYING THE ODD NUMBERS

 1* select * from asd where rowid in (select decode(mod(rownum,2),1,rowid) from asd)
SQL> /

NA   PAYMENTS
-- ----------
aa         23
ee         77
dd         66


FOR EVEN NUMBERS

SQL> select * from asd where rowid in (select decode(mod(rownum,2),0,rowid) from asd);

NA   PAYMENTS
-- ----------
bb         23
cc         55
ff         88

  Was this answer useful?  Yes

ismail mohd

  • Jul 6th, 2007
 

For odd:
SELECT MAX(ROWNUM),EMPNO,ENAME FROM EMP
GROUP BY ROWNUM,EMPNO,ENAME
HAVING MOD(ROWNUM,2)<>0

For even:
SELECT MAX(ROWNUM),EMPNO,ENAME FROM EMP
GROUP BY ROWNUM,EMPNO,ENAME
HAVING MOD(ROWNUM,2)=0

RAMESH

  • Oct 12th, 2011
 

FOR ODD:-

Code
  1.  

FOR EVEN:-
Code
  1.  

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions