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 is the largest value that can be stored in a byte data field?

516


How can I see all tables in sql?

536


Can we join 3 tables in sql?

492


what are rollup and cube in t-sql? : Transact sql

657


What sql database should I use?

547






Explain aggregate functions are available there in sql?

532


What are the different ddl commands in sql?

574


What is a recursive stored procedure?

612


What are the set operators in sql?

546


What language is oracle sql developer?

505


Does a primary key have to be a number?

514


What are properties of the transaction?

552


How can we solve sql error: ora-00904: invalid identifier?

695


Is primary key always clustered index?

532


how can we repair a mysql table? : Sql dba

535