[ticket/12371] Fix SQL query

PHPBB3-12371