Reputation: 93
In SQL Server, how do I select rows 10, 20, 30, 40, etc where the RowID is an equal gap of some integer (+10). There are 50k rows, so using IN (1,10,20,etc) is laborious.
SELECT * FROM 'TABLENAME' WHERE RowID = 10 (+ 10)
Upvotes: 9
Views: 16024
Reputation: 27854
You can use modulo for that.
SELECT * FROM `table` WHERE (`id` % 10) = 0
SELECT * FROM `table` WHERE (`id` MOD 10) = 0
SELECT * FROM `table` WHERE !MOD(`id`, 10)
Anyone should do.
Upvotes: 12
Reputation: 28837
I suspect you need to use the modulus operator rowId mod 10 = 0. something of that order.
Upvotes: 0