[ticket/8323] Combine into a single query

PHPBB3-8323