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 cause of mutating table error and how can we solve it?
What do you mean by stored procedures? How do we use it?
Why do we use set serveroutput on?
Explain autonomous transaction.
How can use stored procedures in sql?
How you improve the performance of sql*loader? : aql loader
How many types of cursors are available in pl/sql?
What does count (*) mean in sql?
Is mariadb nosql?
Can variables be used in sql statements?
what is data manipulation language? : Sql dba
What is meant by user defined function?
How do I order by ascending in sql?
Does truncate table reset auto increment?
What is normalization in a database?