I have the following query:
$max = 3;
$sql = "SELECT *
FROM `prospective_shop` ps
WHERE ps.`approached_by_user` IS NOT NULL
AND ps.`userid`
NOT IN (
SELECT s.userid
FROM `instagram_shop` s
)
ORDER BY ps.`approacheddate` ASC
LIMIT $max
";
$rsm = new ResultSetMappingBuilder($this->_em);
$rsm->addRootEntityFromClassMetadata('App\MainBundle\Entity\ProspectiveShop', 'p');
return $this->_em->createNativeQuery($sql, $rsm)->getResult();
When I try to run this query the process never stops, took a very-very long time, I think there is an error in the:
ORDER BY ps.`approacheddate` ASC
when I remove this LINE everything works well. What is wrong with my query?