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
what are the security recommendations while using mysql? : Sql dba
What information is needed to connect sql*plus an oracle server?
What are analytical functions in sql?
Why indexing is needed?
Is join same as left join?
Which is faster truncate or drop?
what is cross join? : Sql dba
What is the purpose of design view?
i have a column which may contain this kind of value: 123*67_80,12*8889_5,34*8_874 ,12*7_7 (can contain space before a comma, and this string length can be anything) now i want to split this value into two column like: column1: 123*67,12*8889,34*8,12*7 column2: 80,5,874,7 use function for this
What are the limitations of sql express?
How many subqueries can be nested in a statement?
Can 2 queries be executed simultaneously in a distributed database system?
What is a database event trigger?
What is sql query limit?
what are local and global variables and their differences? : Sql dba