Concatenate string in SQL instead of PHP

forward port of https://github.com/owncloud/core/pull/4782