SELECT DISTINCT in Symfony 4

I’m trying to do that query :

SELECT DISTINCT p.reference, p.name, p.range_id 
FROM reference as r INNER JOIN product as p 
WHERE p.reference = r.name;

which will return a single reference name of a table.
I tried with createQueryBuilder

return $this->createQueryBuilder('p')
            ->select('p.reference, p.name, p.id, p.price')->distinct('r.name')
            ->join(Reference::class, 'r', 'WITH', 'p.reference = r.name')
            ->getQuery()
            ->getResult()

and it returns a result but not what I expected. It actually show a result that looks like a SELECT * FROM etc.

I tried a GroupBy by looking at other topics which makes no sense, it doesn’t work anyway.

Thank you for your help !

Source: Symfony4 Questions

Was this helpful?

0 / 0

Leave a Reply 0

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