amend SQL to work on MySQL 8 (Mantis#1909)