Question

I have a big database result set and I want get specific rows from them with 1 Query:

1., 60.

and 61.,120.

and 121.,180.

... and every 60th and 61st record until I have all, the complete result needs to be provided by 1 Query.

Any idea how I can do that?

The LIMIT/OFFSET is not what I'm looking for, as I would need to repeat it many times.

Was it helpful?

Solution

I found an article that uses a single select statement to do this. The statement itself is more complex, but certainly not cryptic by any means.

SELECT *
FROM (
    SELECT
        @row := @row +1 AS rownum, noun
    FROM (
        SELECT @row :=0) r, nouns
    ) ranked
WHERE rownum %4 =1 

Here is the article.

OTHER TIPS

How about

WHERE id % 60 IN ('0','1')

*untested!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top