select * from tabName limit 25
by above query I get 25 rows and I want to add a limit in this result for 5 record per group.
Is it is possible?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
See my answer to How to SELECT the newest four items per category? for the standard solution. This question comes up regularly on StackOverflow, and we try to tag it
greatest-n-per-group. But in most cases, people are asking about the greatest 1 per group, for which different solutions are used.Note that most of the solutions for greatest-n-per-group require you to have some idea of the order of rows in each group, so your query can decide which ones belong in your result set and which ones are the “extras” that should be excluded.
For a solution that doesn’t care about the order, MySQL doesn’t have ANSI SQL:2003 windowing functions, so solving this problem is a little awkward. But you can do it with some user-variable tricks:
Replace
5with any other limit you want to put on the rows per group.