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
How to assign sql query results to pl sql variables?
What is function and procedure?
How do I edit a trigger in sql developer?
Explain the difference between triggers and constraints?
How is a process of pl/sql compiled?
how does a local variable is defined using t-sql? : Transact sql
how to enter numeric values as hex numbers? : Sql dba
explain about mysql and its features. : Sql dba
Why stored procedure is better than query?
Which operator is used in query for pattern matching?
what are properties of a transaction? : Sql dba
What is forward declaration in pl sql?
Is json a nosql?
What is the use of index in sql?
Does inner join remove duplicates?