fixed SQL error on MySQL and PostgreSQL