subConsulta select transformed to DQL

0

I am using MySQL and I have this select :

Select 
TOP 15
Item 
DescriptionforSales
, (select  top 1 Retail from Pricelist where Pricelist.peachitemid = products.peachitemid ) as Retail "
From products where imagen=1 and active=1

When I convert it to dql until here I have no problem:

        $em=$this->getDoctrine()->getManager();
        $dql="SELECT p.ItemID, p.DescriptionforSales
              FROM BackendBundle:Products p";
              $query=$em->createQuery($dql);

        $query=$em->createQuery($dql);
        $query->setMaxResults(15);

The problem is when placing the subquery. Any suggestions?

Greetings

    
asked by juanitourquiza 26.11.2017 в 23:17
source

1 answer

0

The entities had no relationship for this reason, the query is defined in another way, but the result is what is needed in this way:

SELECT p
FROM BackendBundle:Products p
JOIN BackendBundle:Pricelist pl
WITH p.peachitemid =  pl.peachitemid
WHERE p.hasimages =  1
Order by p.bestseller desc

Greetings

    
answered by 27.11.2017 / 01:15
source