I'm trying to query a database to get all initials from a table. In SQL, the query would be:
SELECT SUBSTRING(t.name, 1, 1) AS initial FROM Tool t GROUP BY initial
But using QueryBuilder, I haven't found the way to group by aliases. I've tried:
$q = $this->em->createQueryBuilder()
->select('SUBSTRING(i.name, 1, 1) AS initial')
->from('...\Entity\Tool', 't')
->groupBy('initial');
Error: 'initial' does not point to a Class.
$q = $this->em->createQueryBuilder()
->select('SUBSTRING(t.name, 1, 1)')
->from('...\Entity\Tool', 't')
->groupBy('SUBSTRING(t.name, 1, 1)');
(t.name, 1, ': Error: Cannot group by undefined identification variable.
And after half an hour of looking for documentation I'm asking again for help. Is it possible, or should I go to another way ?