Answer the question
In order to leave comments, you need to log in
Is it possible to do this with one sql query?
There are authors of materials.
Each author has several entries.
It is necessary to make a query so that n records are selected for each author (if there are fewer, then how many there are).
I know how to do this in several requests, but in one it does not work.
I thought in the direction of GROUP_CONCAT, but you cannot impose a condition on it to limit the number of selected elements. Is it even possible?
Thank you all for your help!
Answer the question
In order to leave comments, you need to log in
Sometimes it is more efficient to pre-number user records in a separate field (once the old data and then renumber them again when adding and deleting records), then the query becomes very simple:
select * from статьи t where t.номер<=:limit
It is possible
But the decision with several requests from the client will be much more productive.
Perhaps there is another way to apply the trick with variables ...
select * from статьи t
where :n > (select count(*) from статьи s where s.автор = t.автор and s.id<t.id)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question