Reputation: 734
I have a database table named tickets, I want to fetch every 5000th Number , Like first will be id number 5000 2nd will be 10000 So on.
Upvotes: 2
Views: 158
Reputation: 521194
If the IDs are not continuous you could always simulate row number:
SET @rn=0;
SELECT *
FROM
(
SELECT *, @rn:=@rn+1 AS rn
FROM yourTable
ORDER BY id
) t
WHERE rn % 5000 = 0;
Here is a simplified demo with non continuous id
values showing that this approach can work:
Upvotes: 5
Reputation: 479
If you have a numeric primary key (for example "id"), you could do something like this:
SELECT * FROM tickets WHERE id % 5000 = 0;
Upvotes: 6