title: How correctly can I use sql JOIN and ON statement inside the doctrine addSelect() function
body: <pre><code> public function calculateCandidatesExamScores($examIRI, $groupIRI, int $page =1)
      {
          $firstResult = ($page -1 ) * self::ITEMS_PER_PAGE;
  
          $dql = $this-&gt;createQueryBuilder('examlog');
          $dql-&gt;join('examlog.examQuestion', 'question');
          $dql-&gt;join('question.tblQuestionOptions', 'option');
          $dql-&gt;join('examlog.examUser', 'examRegister');
          $dql-&gt;join('examRegister.userGroup', 'group');
          $dql-&gt;join('examRegister.user', 'candidate');
          $dql-&gt;select('count(examlog.id) totalQuestions, candidate.firstname firstname, candidate.regNumber applicant_ref');
  //        $dql-&gt;addSelect('(SELECT SUM(q.marks) FROM App\Core\Domain\Entity\TblExamUserLogs logs JOIN App\Core\Domain\Entity\TblQuestions q ON logs.examQuestion = q.id JOIN App\Core\Domain\Entity\TblQuestionOptions op ON q.tblQuestionOptions = op.id WHERE logs.answerText = op.answer) AS score');
          $dql-&gt;andWhere('examRegister.exam = :exam AND examRegister.userGroup = :group');
          $dql-&gt;setParameter('exam', $examIRI);
          $dql-&gt;setParameter('group', $groupIRI);
          $dql-&gt;addGroupBy('candidate.firstname, candidate.regNumber');
  //        $dql-&gt;addOrderBy('score', 'DESC');
          $query = $dql-&gt;getQuery()
              -&gt;setFirstResult($firstResult)
              -&gt;setMaxResults(self::ITEMS_PER_PAGE);
  
          $doctrinePaginator = new DoctrinePaginator($query, $fetchJoinCollection = true);
  
  
          return ['totalResults'=&gt; $doctrinePaginator-&gt;count(), 'results'=&gt;$doctrinePaginator-&gt;getQuery()-&gt;getResult()];
  
      }
  
  </code></pre>
  
  <p>The above Query works but if I remove the comment on <code>$dql-&gt;addSelect(...</code> function, it throws the following error <code>Error: Expected Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS, got 'ON' (500 Internal Server Error)</code>. Please I need to know what am doing wrong and the possible way to get this working. Thank you.</p>