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
How exception handling is done in advance pl/sql?
Are sql database names case sensitive?
how does a local variable is defined using t-sql? : Transact sql
Is sql sequential or random?
What is a Mapplet?
What is sql not null constraint?
What is the difference between the sql*loader and import utilities? : aql loader
name 3 ways to get an accurate count of the number of records in a table? : Sql dba
What are the types of subqueries?
In what condition is it good to disable a trigger?
Define overloaded procedure?
What is $$ in sql?
how can we know the count/number of elements of an array? : Sql dba
Explain what is a column in a table?
Can we alter stored procedure?