I'm looking for a way to skip rows in PostgreSQL.
Two ways I could do this are using:
SELECT * FROM table WHERE id % 5 = 0
However I'd have to fetch sequential rows to properly skip. For instance if I fetch row (with ids) 0,3,5, it would not skip 4 out of 5 rows, but instead result in (ids) 0 and 5.
Or skip outside of SQL:
$count = 0;
while($row = progres_fetch_row($result))
if ($count++ % 5 == 0)
// do something
What is the fastest way to get every nth row from a SQL database?
What is the fastest way to get every nth row from a SQL database?Probably using windowed functions, but the most efficient implementation will of course heavily depend on the exact structure of the table(s) in question.