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


Please Help Members By Posting Answers For Below Questions

what are the authentication modes in sql server? How can it be changed? : Sql dba

954


What is lexical units in pl sql?

753


What is prepared statement in sql?

750


Is sql free?

668


What is pl/sql language case sensitive?

822






What is the difference between microsoft access and sql server?

709


Is sql scripting language?

723


how to get a list of columns in an existing table? : Sql dba

709


What do you understand by case manipulation functions?

728


difference between anonymous blocks and sub-programs.

818


How do you explain an index number?

744


Are sql database names case sensitive?

685


Do ddl statements need commit?

724


How do you modify a trigger?

694


How to Declare Fixed Length String Value In PL SQL

841