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 do I view a table in sql?

624


Can you inner join the same table?

617


What is the use of triggers?

631


What is informix sql?

613


What is native sql query?

650






what is the difference between char_length and length? : Sql dba

668


How to Declare Fixed Length String Value In PL SQL

755


What is the size of partition table?

637


Is sql a backend language?

741


Is primary key a clustered index?

620


how to return query output in html format? : Sql dba

746


How does join work in sql?

654


Can we rollback delete command?

596


What are sql injection vulnerabilities?

591


what does it mean to have quoted_identifier on? What are the implications of having it off? : Sql dba

627