Imagine this sample table data ordered by country name:
CustomerID Country
12 Argentina
54 Argentina
20 Austria
59 Austria
50 Belgium
76 Belgium
77 Belgium
15 Brazil
21 Brazil
31 Brazil
34 Brazil
88 Brazil
10 Canada
42 Canada
51 Canada
73 Denmark
74 France
84 France
85 France
1 Germany
6 Germany
17 Germany
37 Ireland
27 Italy
49 Italy
66 Italy
2 Mexico
3 Mexico
How could I paginate it by a limit of no more than 10(has exceptions) with out it returning pages that cut in the middle of country groups. Here is the expected result
variable with page = 1 returns
12 Argentina
54 Argentina
20 Austria
59 Austria
50 Belgium
76 Belgium
77 Belgium
variable with page = 2 returns
15 Brazil
21 Brazil
31 Brazil
34 Brazil
88 Brazil
10 Canada
42 Canada
51 Canada
73 Denmark
variable with page = 3 returns
74 France
84 France
85 France
1 Germany
6 Germany
17 Germany
37 Ireland
variable with page = 4 returns
27 Italy
49 Italy
66 Italy
2 Mexico
3 Mexico
An exception to the limit of 10 is if there are more than 10 rows with the same country.
I tried a couple things with limit and offset but still haven't found any clean/simple query. I am doing this for chunking purposes. Any help is much appreciated. You can play around with the data HERE!