GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Tech FAQs  >  SQL
Go To First  |  Previous Question  |  Next Question 
 SQL  |  Question 193 of 203    Print  
Retrieve Odd and Even Rows
How to retrieve odd and even number of rows from a table?


  
Total Answers and Comments: 2 Last Update: September 25, 2009     Asked by: harpreet.karan 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
February 23, 2009 08:48:44   #1  
usmanahmad Member Since: August 2008   Contribution: 2    

RE: Retrieve Odd and Even Rows
Hi there Thanks for your question if I am not wrong you are asking for odd or even rows based on rownum? Am I right?

If yes then your answer is below

if you are looking for even number rows (based on rownom) then you can use following query.
SELECT usernameFROM (SELECT ROWNUM num usernameFROM dba_users)

WHERE MOD (num 2) 0;

if you are looking odd number rows (based on Rownum) then use following query

SELECT usernameFROM (SELECT ROWNUM num usernameFROM dba_users)WHERE MOD (num 2) 1;

Plase let me know if you have any issue(s).
Thank you.
Usman



 
Is this answer useful? Yes | No
September 25, 2009 06:54:11   #2  
aditya_12 Member Since: August 2009   Contribution: 4    

RE: Retrieve Odd and Even Rows
select * from (select rownum as rwid a.* from (SELECT empno ename job mgr hiredate sal comm deptno from emp) a) where mod(rwid 2) 1


This query will be helpful to find out the odd records for even records just change to mod(rwid 2) 0

Thanks

Aditya

 
Is this answer useful? Yes | No

 Related Questions

Select 1 from dualunionselect 'A' from dual; I guess the query will select zero rows. Is it wrong or right ? if wrong thenWhat will be the result set for the query?Thanks in advance.
Read Answers (4) | Asked by : Rachana

Latest Answer : Answer: Select * from table_name where rowid in (select max(row_id) from table_name) ...
Read Answers (17) | Asked by : A

Latest Answer : FOR EXAMPLE TO RETRIEVE 2ND COLUMN(ENAME)  IN EMP TABLE:SELECT COLUMN_NAME FROM USER_TAB_COLUMNSWHERE TABLE_NAME ='EMP'AND COLUMN_ID = 2 ...

The table name is emp(many fields) with 'designation' as 1 field. my query is i want the percentage of "MANAGERS" in that emp table. (suppose there are 14 rows in total, the rows with 'managers' are 3, so output is (3/14)*100 ).
Read Answers (7) | Asked by : ashwin.k

How to select the all first rows which are having same id.for example:id name salary11. suresh 1000011. suresh 1200012. rajesh 1200012. rajesh 13000now i want to get rows as below given format11. suresh 1000012. rajesh 12000
Read Answers (7) | Asked by : sureshkumar

When we retrieve data from table in SQL Queries, and want to select second, third,........rows from table, then what is the coding of that program?
Read Answers (6) | Asked by : hawasingh

How to delete redundant data from a table & How do we come to know that data or rows is being duplicated with same datavalue in Table.
Read Answers (5) | Asked by : Neeraj

Consider that we r having table name emp....now the question is 1.how should we print the odd rows from that table?2.how should we print the rows where comm=NULL.Reply ASAP
Read Answers (8) | Asked by :

Write a query that display the records based on condition. excluding the record that meets the condition Eg... Select all employees who has same salary as empno 20. My query should return all the rows excluding empno20.
Read Answers (9) | Asked by : brl51274

What is difference between unique index and simple index?is it possible, two rows can have the same unique index? 
Latest Answer : Unique Index:If the index is for a primary or unique key then the owner, name, type, and columns cannot be modified. These properties are all derived from the key constraint. Changing the name of the key constraint will automatically change the name of ...
Read Answers (1) | Asked by : newqtp


 Sponsored Links

 
Related Articles

ODP.NET - Retrieving Multiple Rows on to the Grid

ODP NET Retrieving Multiple Rows on to the Grid In the previous section we tried to retrieve only one row using OracleDataReader In this section we will try to retrieve more than one row or a result set and populate a DataGridView on a WinForm mosgoogle The following code lists out the details of al
 

ODP.NET - Fundamental ODP.NET Classes to Retrieve Data

ODP NET Fundamental ODP NET Classes to Retrieve Data To retrieve data from an Oracle database using ODP NET we need to work with a few of the ODP NET classes At this point we will discuss the most fundamental classes available in ODP NET for retrieving data mosgoogle The following is the list of fun
 

jQuery Expanding and Collapsing Table Rows

jQuery Expanding and Collapsing Table Rows The expanding and collapsing behavior added earlier also conflicts with our filters If a section is collapsed and a new filter is chosen then the matching items are displayed even if in the collapsed section Conversely if the table is filtered and a section
 

jQuery Collapsing and Expanding Table Rows

jQuery Collapsing and Expanding Table Rows When large sets of data are grouped in tables as each year s set of articles are in our News page collapsing or hiding a section s contents can be a convenient way to get a broad view of all of the table s data without having to scroll so much mosgoogle To
 

ODP.NET - Retrieving Multiple Rows on to the Grid

ODP.NET - Retrieving Multiple Rows on to the Grid In the previous section we tried to retrieve only one row using OracleDataReader. In this section we will try to retrieve more than one row or a result set and populate a DataGridView on a WinForm. mosgoogle The following code lists out the details o
 

ODP.NET - Fundamental ODP.NET Classes to Retrieve Data

ODP.NET - Fundamental ODP.NET Classes to Retrieve Data To retrieve data from an Oracle database using ODP.NET we need to work with a few of the ODP.NET classes. At this point we will discuss the most fundamental classes available in ODP.NET for retrieving data. mosgoogle The following is the list of
 

Be Prepared for Tech Job Cuts

Even one of the most flourishing and possibly the strongest industries of the future are not experiencing the economic crunch. The tech industry is now experiencing massive job losses in different categories. Although you will still see innovations almost every day from the tech industry through th
 

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