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 is the largest value that can be stored in a byte data field?
How can I see all tables in sql?
Can we join 3 tables in sql?
what are rollup and cube in t-sql? : Transact sql
What sql database should I use?
Explain aggregate functions are available there in sql?
What are the different ddl commands in sql?
What is a recursive stored procedure?
What are the set operators in sql?
What language is oracle sql developer?
Does a primary key have to be a number?
What are properties of the transaction?
How can we solve sql error: ora-00904: invalid identifier?
Is primary key always clustered index?
how can we repair a mysql table? : Sql dba