[ticket/12366] Include ORDER BY into the query builder

PHPBB3-12366