GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Oracle  >  SQL Plus
Go To First  |  Previous Question  |  Next Question 
 SQL Plus  |  Question 42 of 132    Print  
Display Odd/ Even number of records

  
Total Answers and Comments: 5 Last Update: March 23, 2009   
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
August 10, 2005 08:13:32   #1  
Vijay        

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

 
Is this answer useful? Yes | No
January 21, 2007 05:12:42   #2  
Murali        

RE: Display Odd/ Even number of records

HI

Select rownum empno ename salary from emp group by rownum empno ename salary having Mod(rownum 2) 0 -- Todisplay EVEN records.

Select rownum empno ename salary from emp group by rownum empno ename salary having Mod(rownum 2) 1 -- Todisplay ODD records.

Note : Here u should group all the columns those are in select statement. Here it is rownum empno ename salary etc.

Please feel free to for any queiries

Thanks

Murali.


 
Is this answer useful? Yes | No
June 24, 2008 12:45:40   #3  
sweetytrivedi Member Since: June 2008   Contribution: 7    

RE: Display Odd/ Even number of records
To display the odd/even number of records we can use:

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

Odd:
select * from table_name where (rowid 1) in
(select rowid mod(rownum 2) from table_name);

 
Is this answer useful? Yes | No
June 30, 2008 04:40:49   #4  
nandk.sharma Member Since: June 2008   Contribution: 10    

RE: Display Odd/ Even number of records
We can use the below query to get the odd record of the table --

select r from
(
SELECT rownum r FROM EMP
)

where mod(r 2) ! 0

We can use the below query to get the even record of the table --

select r from
(
SELECT rownum r FROM EMP
)

where mod(r 2) 0


 
Is this answer useful? Yes | No
March 23, 2009 05:58:42   #5  
sharmasl Member Since: March 2009   Contribution: 10    

RE: Display Odd/ Even number of records
These are the querys:-

FOR Odd number of records:

select * from emp where (rowid 1) in (select rowid mod(rownum 2) from emp);

FOR Even number of records:
select * from emp where (rowid 0) in (select rowid mod(rownum 2) from emp);

try.........................


 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape