Friday, 18 December 2015

How to fetch alternate records from a table?

Records can be fetched for both Odd and Even row numbers -.
 To display even numbers-.
 MySQL
 Select studentId from (Select rowno, studentId from student) where mod(rowno,2)=0
1
Select studentId from (Select rowno, studentId from student) where mod(rowno,2)=0
 To display odd numbers-.
 MySQL
Select studentId from (Select rowno, studentId from student) where mod(rowno,2)=1
1
Select studentId from (Select rowno, studentId from student) where mod(rowno,2)=1
 from (Select rowno, studentId from student) where mod(rowno,2)=1.[/sql]

No comments:

Post a Comment