I'm working on PHP project based on Symfony2 and I want this below to works on Symfony2 by Doctrine but actually I get this error by using the "...FROM xx JOIN (SELECT...." :
[Semantical Error] line 0, col 176 near '(
SELECT': Error: Class '(' is not defined.
The final DQL statement that I want to make work is :
return $this->getEntityManager()
->createQuery(
"SELECT u.username, m1.id, n.id as notification, n.vue, u.lastActivity, LEFT(m1.message,60) as Message, m1.lu, m1.dateEnvoi, i.image
FROM MCoreBundle:Messages m1
JOIN (
SELECT m.from, max(dateEnvoi) as dateEnvoi
FROM MCoreBundle:Messages m
JOIN MCoreBundle:User u on m.from = u.id
WHERE m.to = :user
GROUP BY m.from
) t ON m1.from = t.from AND
m1.dateEnvoi = t.dateEnvoi,
MCoreBundle:User u,
MCoreBundle:Notification n,
MCoreBundle:Images i WHERE
u.id = m.from AND
n.id = m.notification AND
i.user = u.id")
->setParameters(array('user' => $iIDUser))
->getResult();
Actual problem : Doctrine/Symfony doesnt recorgnize the "...FROM xx JOIN (SELECT...."