Why Doctrine doesn't work dql, what am I doing wrong?

$query = $entityManager->createQuery(
 'SELECT MAX(employee.salary) FROM
 AppBundle:Employee employee
 JOIN AppBundle:Department department
 WHERE department.id = :id'
 )->setParameter('id', $department->getId());

 $result = $query->getSingleScalarResult();


somehow it's ignoring the comparison department.id = :id and always produces results .

$department->getId() which is equal to 32 only needs to be the result, because it has the employee and nowhere else .How to do that?
June 3rd 19 at 19:06
2 answers
June 3rd 19 at 19:08
Solution
You request the wrong amount. Should be something like this (I assume you have configured the relationship @ManyToOne between Employee and Department):

SELECT MAX(employee.salary)
FROM AppBundle:Employee employee
JOIN for employee.department department
WHERE department.id = :id


You can do without additional connections, if you use the DQL-function IDENTITY:

SELECT MAX(employee.salary)
FROM AppBundle:Employee employee
WHERE IDENTITY(employee.department) = :id
June 3rd 19 at 19:10
I tried using Native sql to do, it does not give the result . Although the same query in console works as it should

Find more questions by tags Doctrine ORMSymfony