Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I select every nth row?

Tags:

sql

sqlite

modulo

My table has 81,225 rows. I am trying to select every 285th row:

Select *
From Test A
Where ROWID  > 0 AND ROWID <= 81225
AND ROWID % 285 = 285 % 285

This query returns 285 rows as expected, but not the correct ones. What needs to be changed?

like image 683
Nick Johnson Avatar asked Oct 27 '25 00:10

Nick Johnson


1 Answers

The condition you are using for the modulus is wrong. Use this instead:

Select *
From Test A
Where ROWID  > 0 AND ROWID <= 81225
AND ROWID % 285 = 0
like image 116
Tim Biegeleisen Avatar answered Oct 28 '25 15:10

Tim Biegeleisen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!