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
Which table is left in join?
What is use of trigger?
how can we know the number of days between two given dates using mysql? : Sql dba
What does closing a cursor do?
What is difference between nchar and nvarchar?
How does cross join work in sql?
explain primary keys and auto increment fields in mysql : sql dba
How long does it take to learn pl sql?
How do you rename a table in sql?
What does trigger mean in slang?
explain the difference between bool, tinyint and bit. : Sql dba
what is a primary key? : Sql dba
Is natural join and inner join same?
What is sql trigger example?
How do you update sql?