[ticket/12174] Update sql query

PHPBB3-12174