Answer the question
In order to leave comments, you need to log in
How to do SELECT COUNT(DISTINCT(field1, field2)) in Doctrine2 DQL?
In a native PostgreSQL query, you can easily do
SELECT COUNT(DISTINCT(t.field1, t.field2)) FROM table t;
QueryException: [Syntax Error] line 0, col 22: Error: Expected Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS, got 'o'
Answer the question
In order to leave comments, you need to log in
First, the parentheses are not needed for the DISTINCT expression.
Secondly, DISTINCT in Doctrine does not support multiple arguments
. Thirdly, there is a hack to solve the previous two:
SELECT COUNT(DISTINCT CONCAT(t.field1, t.field2)) FROM table t;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question