|Select Alternate Row SQL Server|
Their are many approaches to get alternate record from SQL server database table. Here i have discussed 2 approaches
1. Complex Query
2. Using Views
Complex Query: SELECT * from (SELECT ROW_NUMBER() OVER(ORDER BY Employee_id) as RowNumber, * from employees) T where t.RowNumber%2=0
CREATE VIEW with_rownumber
SELECT ROW_NUMBER() OVER(ORDER BY Employee_id) as RowNumber,* from employees;
SELECT * from with_rownumber where RowNumber%2=0
The approach preferred here is using VIEW because:
1. Easy to understand.
2. In future if you need to perform any operation related to RowNumber then you don't need to create another complex query. You could use view having rownumber column in it.