Is it possible to do this in one sql query?

Have the authors of the materials.
Each author has several records.
You need to make a query to for each author was chosen for n records (if less than what is).
How to do it in multiple queries I know, but one does not work.
Thought in the direction of GROUP_CONCAT, but it is impossible to impose a condition to limit the number of selectable items. Is it even possible?
Thank you all for the help!
October 8th 19 at 00:34
4 answers
October 8th 19 at 00:36
Solution
Thank you! - Lucile79 commented on October 8th 19 at 00:39
October 8th 19 at 00:38
Thank you very much! - Lucile79 commented on October 8th 19 at 00:41
October 8th 19 at 00:40
It is sometimes better to pre-enumerate the user accounts in a separate field (once the old data and then when adding and deleting entries to re-order), then the query will be very simple:
select * from article t where t.number<=:limit
but if the limit will not change with time, then enough field of type boolean - Lucile79 commented on October 8th 19 at 00:43
I do not quite understand what was going on. Could you explain what is the effectiveness of to number lines and how this affects the task? - Lucile79 commented on October 8th 19 at 00:46
rPman, it sometimes would be more efficient in exactly one case: if all authors write in sequential order, one after another, no more than one record at a time. What if we have 3 authors, we need to select 5 records in each, but one of the authors we write 20 articles a day, and the other two times a week writing? Then we get the last 15 entries of the same author.

Plus you and a sample SQL query resulted incorrect, correctly based on your algorithm should be:
SELECT * FROM articles t ORDER BY t.room DESC LIMIT :limit;
- jaunita commented on October 8th 19 at 00:49
ruskar, number can be different. Can be numbered and in the context of the author. When the author adds the article to renumber all of its articles, i.e. the sequence number of this approach will be unique only in the context of the author. I think it meant rPman. And request him to change is not necessary. You just don't get the idea. - Lucile79 commented on October 8th 19 at 00:52
I don't understand what was going on in this specific case. Why number of entries and what this implies. - Jessik commented on October 8th 19 at 00:55
ruskar errors in my query, no, you misunderstood the idea.

When an article is added it is assigned the number equal to +1 to the number of his last (if the articles is not 0). Deleting articles all rooms for articles of the author after being removed decreased by 1.

p.s. The basic idea (it almost always can be applied) — if the read request is slow, count it (or part of it) in advance during recording. - Logan_Reilly commented on October 8th 19 at 00:58
October 8th 19 at 00:42
Can

select * from article t <br> where :n > (select count(*) from articles where s s.author = t.the author and s.id<t.id)< code><br> <br / > But the solution with multiple requests from the client will be much more productive.<br> <br / > Perhaps there is something you can apply a trick with variables...</t.id)<>
Thank you! - Lucile79 commented on October 8th 19 at 00:45

Find more questions by tags SQLMySQL