How One can easily select all even, odd, or Nth rows from a
table using SQL queries?

Answer Posted / guru

Please Use Below Query and Kindly post reply feedback

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,0) in (select rowid,
mod(rownum,10) from emp)

Is This Answer Correct ?    18 Yes 8 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to assign sql query results to pl sql variables?

507


What is function and procedure?

562


How do I edit a trigger in sql developer?

535


Explain the difference between triggers and constraints?

514


How is a process of pl/sql compiled?

594






how does a local variable is defined using t-sql? : Transact sql

537


how to enter numeric values as hex numbers? : Sql dba

563


explain about mysql and its features. : Sql dba

543


Why stored procedure is better than query?

505


Which operator is used in query for pattern matching?

620


what are properties of a transaction? : Sql dba

557


What is forward declaration in pl sql?

586


Is json a nosql?

537


What is the use of index in sql?

551


Does inner join remove duplicates?

516