GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Oracle  >  SQL
Go To First  |  Previous Question  |  Next Question 
 SQL  |  Question 139 of 171    Print  
Write a query to display alternate records from the employee table?

  
Total Answers and Comments: 6 Last Update: July 09, 2008     Asked by: kowmudiswarna 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: mohdfarezpink
 
select count(*), rownum
from emps
group by rownum
having mod(rowmum,2) = 1

output:-

1      1
1      3
1      5
1      7
1      8
.
.
.
.
.

Above answer was rated as good by the following members:
M.REHMAN, praveentn
September 19, 2007 10:02:13   #1  
kowmudiswarna Member Since: September 2007   Contribution: 21    

RE: Write a query to display alternate records from th...
SELECT * FROM emp WHERE (rowid 1) IN (SELECT rowid mod(rownum 2) FROM emp);
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
October 15, 2007 01:46:27   #2  
manish dudhe        

RE: Write a query to display alternate records from th...
--odd number query

SELECT *
FROM ( SELECT rownum rn empno ename
FROM emp
) temp
WHERE MOD(temp.rn 2) 1

--even number query


SELECT *
FROM ( SELECT rownum rn empno ename
FROM emp
) temp
WHERE MOD(temp.rn 3) 0

 
Is this answer useful? Yes | No
January 14, 2008 03:37:57   #3  
mohdfarezpink Member Since: January 2008   Contribution: 4    

RE: Write a query to display alternate records from the employee table?
select count(*) rownum
from emps
group by rownum
having mod(rowmum 2) 1

output:-

1 1
1 3
1 5
1 7
1 8
.
.
.
.
.

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
May 25, 2008 16:18:50   #4  
M.REHMAN Member Since: May 2008   Contribution: 3    

RE: Write a query to display alternate records from the employee table?
select * from employeeswhere employee_id in (105 160 148 165 175 206);
 
Is this answer useful? Yes | No
July 08, 2008 02:02:59   #5  
sgbang Member Since: July 2008   Contribution: 2    

RE: Write a query to display alternate records from the employee table?
Hi Guys

You can use this query also

select * from employees where employee_id in (
select decode(mod(rownum 2) x employee_id null) emp_id from employees)
/

where x 0 for even records
where x 1 for odd records

Regards

Snehasish

 
Is this answer useful? Yes | No
July 08, 2008 23:27:54   #6  
ammupriyaa Member Since: July 2008   Contribution: 5    

RE: Write a query to display alternate records from the employee table?
To Display even row numbers
---------------------------
select * from emp where (rowid 0) in (select rowid mod(rownum 2) from emp )


To Display odd row numbers
---------------------------
select * from emp where (rowid 1) in (select rowid mod(rownum 2) from emp )


 
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