Suppose you have a table of employee details consisting of columns names (employeeId, employeeName), and you want to fetch alternate records from a table. How do you think you can perform this task? | Eklavya Online

Suppose you have a table of employee details consisting of columns names (employeeId, employeeName), and you want to fetch alternate records from a table. How do you think you can perform this task?

You can fetch alternate tuples by using the row number of the tuple. Let us say if we want to display the employeeId, of even records, then you can use the mod function and simply write the following query:

1 Select employeeId from (Select rownumber, employeeId from employee) where mod(rownumber,2)=0
where ‘employee’ is the table name.

Similarly, if you want to display the employeeId of odd records, then you can write the following query

2 Select employeeId from (Select rownumber, employeeId from employee) where mod(rownumber ,2)=1