Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9221525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:35:54+00:00 2026-06-18T03:35:54+00:00

I have a basic table article linked to a table category by id (classic),

  • 0

I have a basic table article linked to a table category by id (classic), I would like to make a doctrine request to retrieve only 5 articles by category (for all categories)

This request return me all articles of categories, I just want 5 for each

public function getArticlesAndCategs(){
    $qb = $this->createQueryBuilder('c')
            ->orderBy('c.id','DESC')
                ->leftJoin('c.articles', 'a')
                ->addSelect('a')
                ->addOrderBy('a.id','DESC')
            ->getQuery();
    return $qb->execute();                
}

Can you help me for that?
thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:35:55+00:00Added an answer on June 18, 2026 at 3:35 am

    This is no easy task unfortunately. At least I haven’t found a satisfying solution yet (satysfying for me 😉 ).

    Three things you can do:

    1. Iterate through the categories and retrieve 5 posts for each category. This of course cause that many db request as many you have categories.

    2. Return all the categories with joined posts and iterate inside php. The drawback – you’ll return all the posts, so if you have many, this can mean a lot of memory used.

    3. If you don’t have to stick to Doctrine you can try the solution from here: mySQL Returning the top 5 of each category

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a basic string with holds a html table. The table looks like
I have a messaging system (very basic) that has a table like this: **MESSAGE_ID**
Lets say I have your basic table layout (like below). How to I grab
I have a basic table with two columns: name and value. I'd like to
I have a basic table that looks like the following: SQL> desc comments Name
I have a very basic Table structure to be placed in middle/center of the
I have a fairly basic data.table in R, with 250k rows and 90 columns.
I have a very basic mysql table called memberships, that tracks which people belong
I have this table, which can be seen as a basic custom gantt chart:
I'm working on a very basic shopping cart system. I have a table items

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.