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 are the authentication modes in sql server? How can it be changed? : Sql dba
What is lexical units in pl sql?
What is prepared statement in sql?
Is sql free?
What is pl/sql language case sensitive?
What is the difference between microsoft access and sql server?
Is sql scripting language?
how to get a list of columns in an existing table? : Sql dba
What do you understand by case manipulation functions?
difference between anonymous blocks and sub-programs.
How do you explain an index number?
Are sql database names case sensitive?
Do ddl statements need commit?
How do you modify a trigger?
How to Declare Fixed Length String Value In PL SQL