G
G
Grigory Vasilkov2017-08-29 16:50:38
SQL
Grigory Vasilkov, 2017-08-29 16:50:38

How to select different number of records from two tables and make summary pagination?

The question is more about SQL databases, but in general I can’t figure out how it should be, maybe someone has already done it?
There are two tables - one contains a collection of products with personal pages, the other - without personal pages.
The task is to display a smaller list with urls (100 entries) and a larger list without urls (1000 entries), while doing pagination so that pagination does not lose any of the lists between pages.
UNION query swears that LIMIT is unacceptable between two tables.
If you do not do LIMIT, then the entire first table (2 million) will be in front of the second table (also 2 million), as a result, LIMIT 1100 will pull 1100 records from the first table, but you need 100 from that and 1000 from this one.
How to be here at all?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Cheremisin, 2017-08-29
@gzhegow

Make separate current page variables for these two lists, page_l1 and page_l2 for example.
Well, for good, you can calculate one navigation for two lists at once.
For example, in one table there are 20000123 records, in the second 123450, we equate to a larger table and its display in 1000 records, then
20000123/1000=123450/X
X = (123450 * 1000) / 20000123 = 6
Total for 1000 records from the larger table, we will show 6 records out of a smaller one.
The problem is that if the smaller table is much shorter, then we will have to select one record from it, and at the very end of pagination we will not have a list from the smaller table at all.
PS. Correct your calculations if wrong

A
aol-nnov, 2017-08-29
@aol-nnov

well, select them with two queries and combine them on the backend, that's business!..

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question