V
V
Vadim2018-02-05 18:33:30
MySQL
Vadim, 2018-02-05 18:33:30

How to make pagination with join?

There is an entity with several associations, I need to display several, for example, 20 main entities and all their associations. If you do LIMIT OFFSET, then all of them are displayed in the database in a row and, accordingly, everything is cut off except for the first 20 lines, among which there can be records related to only one, first, main entity.
Let's say the main entity is User and Orders association.
It will be like this:

1) Пользователь1, Заказ1
2) Пользователь1, Заказ2
3) Пользователь2, Заказ5
4) Пользователь2, Заказ6
5) Пользователь2, Заказ11
6) Пользователь3, Зазаз29

and LIMIT 3, then this will give me only user1 with all his orders and user2 with an incomplete set of orders, but you need 3 users and each with a full set of orders and so that the WHERE conditions do not break, because if done with a subquery: first select three user, and then joins to them, where will not work.
How to be?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vadim, 2018-02-09
@vadimek

Of course, so , I completely forgot that there the second parameter makes this possible, and by default.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question