try to optimize query re #3239

git-svn-id: svn://develop.studip.de/studip/trunk@25503 c5b85792-5220-0410-ad23-ed5b6b8ad999