You cannot put a subquery in the FROM your DQL.
I assume your PC {uuid, locale} , as well as the discussion with you in the IRC. Since you also have two different columns in your query, this can become ugly. What you can do is put it in a WHERE :
select e from MyEntity e WHERE e.uuid IN ( select e2.uuid from MyEntity e2 where e2.locale IN (:selectedLocales) group by e2.uuid ) AND e.locale IN ( select max(e3.locale) as locale from MyEntity e3 where e3.locale IN (:selectedLocales) group by e3.uuid )
Note that I used a comparison with a (non-empty) array of locales to which you are attached to :selectedLocales . This is done in order to avoid destroying the query cache if you want to combine it with additional locales.
I also do not suggest creating this using the query builder if there is no real advantage in this, since it will simply simplify the splitting of the query cache if you add conditional expressions dynamically (this is also connected with 3 query builders!)
source share