Symfony 4 – How to Order BY but DISTINCT and a 2nd ORDER BY – Createquerybuilder?

I am training on Symvony and CREATEQUERYBUILDER, I was ordering by a field to display data
I want to display data ORDERED BY Quantity left in stock but I want them also "grouped by" package ID.

I don’t know how to group by but still display all the other products (like in my 2nd pic)

If I don’t GROUP BY, I get all the data but it doesn’t respect "GROUP BY" package ID and product from package 1 and package 2 are entangled.
Without a GROUP BY

What I do is:

    public function findAllOrderByQuantity(): array
    $qb = $this->createQueryBuilder('pack')
        ->orderBy( 'pack.quantity', 'ASC')

    $query = $qb->getQuery();
    return $query->execute();

Could you please help me on that one? Thanks

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *