Symfony2 subquery within Doctrine entity manager
I need to perform this query: SELECT * FROM (SELECT * FROM product WHERE car = 'large' ORDER BY onSale DESC) AS product_ordered GROUP BY type In Symfony2 using the entity manager. My basic query builder would be : $query = $em->getRepository('AutomotiveBundle:Car') ->createQueryBuilder('p') ->where('pr.car = ?1') ->andWhere('pr.status = 1') ->orderBy('pr.onSale', 'DESC') ->setParameter(1, $product->getName()) ->groupBy('p.type') ->getQuery(); But I cannot work out how to add in a subquery to this. Ive tried making a separate query and joining it like: ->andWhere($query->expr()->in('pr.car = ?1