Problem with offset and MySQL limit

1

When I make a query using limit and offset, the database returns one line less than it should. What is the problem? Cache? Lock Index? Data?

For example:

select distinct(id_table1) from table_1
join table_2 on table_2.id_table2 = table1.id_table2
where table2.campo = numero_qualquer
limit 100
offset 523800;

The above query returns 99 results instead of 100.

If I make the same query with limit 1 and offset 523842 it returns 0 results. Note that if I raise the limit to 2 it returns 1. I do not know why this line is not displayed it is apparently counted by the offset to jump but not displayed in the limit result.

The tables are in MyISAM, I have already fixed index and data and nothing works.

    
asked by anonymous 23.05.2018 / 01:40

1 answer

0

The problem is that when you make a LIMIT with GROUP_BY or DISTINCT the OFFSET changes according to the grouping created. then id 523800 does not refer to his position in the TABELA but his position in the cluster, so when the cluster was created, you may not have 100 more records from that index, but only 99.

Try to increase the number of LIMIT to 200, it will remain 99.

    
23.05.2018 / 21:52