Write an SQL query to fetch 5th ,10th,15th .. records from a table?
- User
Write an SQL query to fetch 5th ,10th,15th .. records from a table?
- Assistant
To fetch every 5th record (i.e., the 5th, 10th, 15th, etc.) from a table in SQL, you can use the
ROW_NUMBER()window function to assign a sequential integer to each row based on a specified order. Then, you can filter the rows where the row number is divisible by 5.Here is an example SQL query that demonstrates this approach:
SELECT * FROM ( SELECT *, ROW_NUMBER() OVER (ORDER BY some_column) AS RowNum FROM YourTable ) sub WHERE RowNum % 5 = 0;
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.