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
What pl/sql package consists of?
What are tables in sql?
What is rownum?
How can we implement rollback or commit statement in a trigger?
What are all the common sql functions?
What are the ways on commenting in a pl/sql code?
How to return multiple rows from the stored procedure?
What is the main reason behind using an index?
What is the use of partition by in sql?
Is sql harder than python?
What is posting?
Why truncate is used in sql?
What does a pl/sql package consist of?
How does postgresql compare to mysql?
in oracle 10g sw after compiling procedure how to pass parameter values ,if we (v_empid out number)how to give empid after successful compilation program.This site exact suitable for 10g with respect to question & answer same format , im trying sql browser & sql command prompt using exec procedure name & respective parameters.