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
When is the explicit cursor used ?
Why procedure is used in sql?
How to avoid duplicate records in a query?
What is cross join sql?
Does mysql support pl sql?
I need a function for a train ticket reservation please answer it thanks in advance
How does one use sql*loader to load images, sound clips and documents? : aql loader
What is an intersect?
Why does sql need a server?
Why schema is used in sql?
What is nosql db?
Can I copy :old and :new pseudo-records in/to an oracle stored procedure?
What is data profiling in sql?
What are different types of triggers?
What is the difference between sum and count in sql?