How One can easily select all even, odd, or Nth rows from a
table using SQL queries?

Answer Posted / mritunjay

hi..mr guru all are correct except for the Ntn row
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
For nth number,
Example we r considering number n=10
select * from emp where (rowid,1) in (select rowid,
rownum/:N) from emp)

Is This Answer Correct ?    12 Yes 8 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How exception handling is done in advance pl/sql?

593


Are sql database names case sensitive?

598


how does a local variable is defined using t-sql? : Transact sql

640


Is sql sequential or random?

655


What is a Mapplet?

740






What is sql not null constraint?

683


What is the difference between the sql*loader and import utilities? : aql loader

670


name 3 ways to get an accurate count of the number of records in a table? : Sql dba

661


What are the types of subqueries?

664


In what condition is it good to disable a trigger?

652


Define overloaded procedure?

703


What is $$ in sql?

643


how can we know the count/number of elements of an array? : Sql dba

665


Explain what is a column in a table?

674


Can we alter stored procedure?

636